?
Solved

WM_TIMER - different thread, separate entity?

Posted on 2006-06-05
4
Medium Priority
?
570 Views
Last Modified: 2013-11-20
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?
0
Comment
Question by:Lescha
  • 2
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 total points
ID: 16835193
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
 
LVL 1

Author Comment

by:Lescha
ID: 16839604
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 16840033
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
 
LVL 1

Author Comment

by:Lescha
ID: 16840061
Thanks a bunch! (Mostly, for explaining the modal/messages thing).
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …
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.
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

850 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