Re: My window doesn't re-display itself
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 21 Jul 2008 14:17:38 -0400
Generally, when you start thinking about putting PeekMessage calls in, this is strongly
suggestive of the wrong approach to the design entirely. If there is a long computation
it should be done in a background thread.
joe
On Mon, 21 Jul 2008 08:10:30 -0700 (PDT), Mikel <mikel.luri@xxxxxxxxx> wrote:
On 21 jul, 16:15, Mike Silva <snarflem...@xxxxxxxxx> wrote:Joseph M. Newcomer [MVP]
Hi,
I have written some utilities as MFC dialog apps. They will typically
loop through some list doing things to various files, and listing
their progress in static text windows (info such as current file name,
number of files processed, number of files remaining). The apps do
what they're supposed to and everything is fine, and the status
displays work properly, except...
If, while my utility app is processing files, I select another app,
e.g. check my email or browse the web, and then select the utility app
again, the display does not refresh - all I get is a completely blank
dialog box. The windows and controls inside the dialog box only
refresh when the utility is finished running. If I never navigate
away from the utility app, the display keeps updating as expected and
designed.
So, what do I need to do (perhaps after each file is processed) to
assure that my display is responsive and everything will re-display
when the app window goes from inactive to active? Thanks.
Mike
Well, the quick n' dirty way would be to do something like the
following after each file (or after every N files):
while (::PeekMessage(&msg, NULL,0,0,PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
However, the *right* way would be to create a worker thread to process
the files. Thus, the UI won't freeze.
Take a look at Joseph M. Newcomer's essay on worker threads at
www.flounder.com/workerthreads.htm
It seems more complicated (and it is) but things work fine if done
right.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- My window doesn't re-display itself
- From: Mike Silva
- Re: My window doesn't re-display itself
- From: Mikel
- My window doesn't re-display itself
- Prev by Date: Re: How to capture VK_UP key in CEdit derived class
- Next by Date: Re: How to recreate the view after loading a document
- Previous by thread: Re: My window doesn't re-display itself
- Next by thread: How to capture VK_UP key in CEdit derived class
- Index(es):
Relevant Pages
|