WM_TIMER - different thread, separate entity?

Posted on 2006-06-05
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(...)

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?
Question by:Lescha
    LVL 48

    Accepted Solution

    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


    if ( ! m_bMessageBoxIsActive )
        m_bMessageBoxIsActive = TRUE;
        m_bMessageBoxIsActive = FALSE;

    LVL 1

    Author Comment

    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?
    LVL 48

    Expert Comment

    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.
    LVL 1

    Author Comment

    Thanks a bunch! (Mostly, for explaining the modal/messages thing).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    Suggested Solutions

    Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    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.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now