MFC: Loop within OnXYZ methods

This is a discussion on MFC: Loop within OnXYZ methods within the Windows Programming forums, part of the Platform Specific Boards category; Hi all!, I want to do some operations after a button has been clicked. The operation needs some calls to ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    47

    Question MFC: Loop within OnXYZ methods

    Hi all!,

    I want to do some operations after a button has been clicked.
    The operation needs some calls to return a true so it can be returned from this method.
    Code sample:

    Code:
    void CTerraformer::OnButtonFormTerra() 
    {
    	while (!m_bDone)
    	{
    		m_bDone = makeSomeOperationsHere();
    		
    		MSG msg;
    		while (PeekMessage(&msg, NULL, 0, 0, true))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    }
    I saw a construct like the code sample above and to me it looks like
    a mixture of MFC and pure WIN32 API programming.

    My question: Is this a clean way to code MFC ???

    Regards,
    Robert

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Actually that's pure API inside a class member function, using the MFC class naming convention (but that might be coincidence).

    And no, it doesn't look like clean coding to me. A message loop somewhere in a stray place can't be clean.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    i thought the same, ... any suggestions how make it
    to be a clean code ?

    -
    Robert

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    It's a larger issue. I would guess removing the message loop and calling the method differently (from a different place/thread) should solve it. But that's an issue of program design, not just a single method.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 11:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 01:13 AM
  3. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 04:09 PM
  4. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 04:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21