WM_TIMER - different thread, separate entity?

Does SetTimer open a new thread? If not, can anyone explain to me why AfxMessageBox inside of OnTimer does not prevent further calls to OnTimer? In other words,

void OnTimer(...)
{
  ...
  AfxMessageBox(...);
  ...
}

The message box appears... and then appears again, and again, without waiting for me to close the first one. It's like Windows is trying to process the next WM_TIMER message without waiting for the current on to complete.

If this is what happens, is there a normal way to prevent it? In other words, how can I block the timer without actually killing it?
LVL 1
LeschaAsked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
All Windows messages, including WM_TIMER, are handled in the main thread. Timer itself can run in it's own thread, but messages sent by timer are handled in the main thread, like any message.

MessageBox is modal dialog. Every modal dialog has it's own message loop. When modal dialog is active, other windows continue to handle messages. However, parent window of modal dialog is disabled, and doesn't react on mouse and keyboard messages.

I don't see the way to block the timer without killing it. But you can use flag which prevents another message box to be shown.

BOOL m_bMessageBoxIsActive;   // class member, set to FALSE in constructor

OnTimer:

if ( ! m_bMessageBoxIsActive )
{
    m_bMessageBoxIsActive = TRUE;
    AfxMessageBox(...);
    m_bMessageBoxIsActive = FALSE;
}

0
 
LeschaAuthor Commented:
So... what you're saying is that a modal dialog box prevents only mouse/keyboard to the parent window? All the other messages are passed and handled?

By inference, a system modal dialog box will probably prevent the mouse/keyboard from all (or most of) the windows of the system, but not their other messages?
0
 
AlexFMCommented:
1. Yes. When modal daialog is active, all other windows properly paint themself, this means, they handle WM_PAINT messag. Other messages, like WM_TIMER, are handled as well.

2. MB_SYSTEMMODAL is the same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. It doesn't block all windows of the system.
0
 
LeschaAuthor Commented:
Thanks a bunch! (Mostly, for explaining the modal/messages thing).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.