Solved

Designing a well behaved MFC dialog app

Posted on 2003-11-24
8
247 Views
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.
0
Comment
Question by:johnsla
  • 3
8 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 63 total points
Comment Utility
The article at http://www.codeguru.com/misc/lenop.html describes how to use create a multi-threaded application to solve your problem.
0
 
LVL 23

Assisted Solution

by:Roshan Davis
Roshan Davis earned 62 total points
Comment Utility
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) )
            {
                  ::TranslateMessage(&msg);
                  ::DispatchMessage(&msg);
            }

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

Good Luck
0
 

Author Comment

by:johnsla
Comment Utility
Nope.  Did not do the trick.  Regardless of where I put this code
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
I provided at least part of the solution.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 88
lucky13 challenge 11 111
either24  challenge 19 83
wait notify demo infinite loop 3 79
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

7 Experts available now in Live!

Get 1:1 Help Now