Designing a well behaved MFC dialog app

Posted on 2003-11-24
Last Modified: 2013-11-20
OK.  What am I doing wrong.  Why is it when I create an MFC app that is performing a process I cannot move the dialog box, repaint the screen when another app gets the focus and covers mine, or get the Cancel key to kill the app.  There must be some polling issue I'm missing and should implement.
Question by:johnsla
  • 3
LVL 44

Accepted Solution

Karl Heinz Kremer earned 63 total points
ID: 9814871
The article at describes how to use create a multi-threaded application to solve your problem.
LVL 23

Assisted Solution

by:Roshan Davis
Roshan Davis earned 62 total points
ID: 9815750
If you are using a lengthy for loop, this will block windows messaging....So add this code in that loop

            MSG msg;

            while ( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )

      The above code will process the message queue along with that heavy processing

Good Luck

Author Comment

ID: 9819565
Nope.  Did not do the trick.  Regardless of where I put this code
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 9820771
Assuming that the Peek/Translate/DispatchMessage construct does work, you have to put it inside your process, so that it gets executed every now and then (how often depends on how quickly the application should respond). So for example, if you are performing a lengthly calculation in a loop, you have to execute this code inside your processing loop:

while (!done)
   if (counter % 1000 == 0)
      while (::PeekMessage((&msg, NULL, NULL, NULL, PM_REMOVE)
// do your calculation

If this still does not work, take a look at the link that I posted earlier. The threaded approach should work regardless of what you do in your worker process.
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11848129
I provided at least part of the solution.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
viewing source code from eclipse 13 88
Use of condition with 'serial' in ansible 2 49
How to convert MFC::CString to UTF8 wchar_t* 10 141
Not needed 13 93
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now