Link to home
Start Free TrialLog in
Avatar of johnsla
johnsla

asked on

Designing a well behaved MFC dialog app

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.
ASKER CERTIFIED SOLUTION
Avatar of Karl Heinz Kremer
Karl Heinz Kremer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnsla
johnsla

ASKER

Nope.  Did not do the trick.  Regardless of where I put this code
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)
      {
         ::TranslateMessage(&msg);
         ::DispatchMessage(&msg);
      }
// 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.
I provided at least part of the solution.