Re: PeekMessage not working as desired!
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Thu, 14 Dec 2006 15:32:05 -0500
See below...
On Thu, 14 Dec 2006 13:14:50 +0100, Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx> wrote:
vkinra@xxxxxxxxxxx wrote:****
We have a situation where we need to process UI input in a separate UI
thread rather than the main thread.
There is no such thing as a main thread, all threads are at first equal. If
you use the initial thread or another thread for UI is up to you, just make
sure that you don't share UI stuff between threads.
Actually, that's not true in CE. There really is a "main thread", and unlike regular
Windows, if the main thread terminates, the app terminates (it strikes me that the CE
people hadn't read the specifications when they implemented this misfeature).
Which does not change the fact that there is absolutely no parent-child relationship as
the OP seems to want to rely on. Secondary threads are just secondary threads.
****
****
Ours is a MFC application running on Windows CE. Since,
AttachThreadInput is not available, I tried using PeekMessage.
In MainFrame OnCreate I created a UI Thread using AfxBeginThread.
Okay, at that point, the thread invoking OnCreate is already bound to be the
UI thread.
This thread (AnimationThread) basically displays a busy
icon which the user can hit to cancel an operation in the main thread
(I realize this method is counter intuitive, but we had to do it this
way).
Hmmm, the normal way is to start a worker thread which does the long
operation and then MsgWaitForSingleObject() for that thread to finish,
keeping the message queue of the window alive. You then react to a cancel
request by somehow interrupting the worker thread. If the worker thread is
displaying an animation, you need some shared picture queue where it places
pictures and then tells the UI to update itself with a message.
Actually, the normal way is to start a worker thread which does the long computation and
immediately return to the message loop *without* doing a WFSO. Doing a WaitFor...
waiting for a thread to finish defeats the value of having a thread, and blocks the GUI,
and is fundamentally bad design. It is inconsistent with keeping the message queue window
alive. But I agree with you that the real problem stems for doing the design backwards.
****
****
Note: in such cases, a timer instead of another thread is much easier to
handle!
Timers are generally too coarse, and too unpredictable, to support animation effects well.
****
*****
My frustration is that I had this working before but then I
started [...] but in the process, I broke something. Now I cannot
figure out at all why PeekMessage does not work.
Version control systems exist for such cases, I'd suggest using Subversion
and TortoiseSVN as frontend.
Actually, I'm surprised that it ever "worked", since nothing you've described here can
work.
****
Joseph M. Newcomer [MVP]
Uli
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Re: PeekMessage not working as desired!
- Next by Date: valid rtf file that includes a dib
- Previous by thread: Re: PeekMessage not working as desired!
- Next by thread: Unicode DLL (MFC extension)
- Index(es):
Relevant Pages
|