Thread: MFC: Loop within OnXYZ methods

  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,895
    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,895
    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, 10:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Lesson #5 - Methods
    By oval in forum C# Programming
    Replies: 1
    Last Post: 05-04-2006, 03: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, 03:45 PM