I'm creating a simple win32 program with one main window and a modeless dialog.
I know that using IsDialogMessage() the program will dispatches messages to modeless window (like keyboard events).
// step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
if(!IsDialogMessage(g_hToolbar, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
But without using IsDialogMessage(), the modeless window still get events like click and some other events dispatched by the mouse.
Why? How can this modeless get these messages if the main loop isn't dispatching messages to it?
I just want to know how it works internally.
IsDialogMessage filters out some of the messages, but allows most messages to hit the TranslateMessage / DispatchMessage part of the message loop and be dispatched normally.
The reason that IsDialogMessage has to process some messages is that the messages were going to be delivered to the wrong window.
Consider - normally - keypress messages are delivered to the control with focus. However, the tab keystroke is meant to move focus to the next control on the dialog. Rather than making every control have to process tabbing, IsDialogMessage catches tab keystrokes before they are delivered to the actual currently focused control, and ensures that the dialog box code handles the tab logic.
Most other messages - mouse overs and painting and so on - are going to be delivered to the dialog boxes window proc anyway - and so are handled the normal way. Its really just the subset of messages that were destined to be sent to controls, but need to be handled by the dialog box, that IsDialogMessage filters out and processes.
A modal window will disable its parent window, the fact that your HWND is called g_hToolbar tells me that this is not a modal dialog...
Modal dialogs (DialogBox*) create their own message loop (And work like MessageBox etc), you must be talking about modeless dialogs (CreateDialog*) You will get all messages from the window manager without IsDialogMessage, IsDialogMessage performs dialog manager tasks like handling TAB and default button focus.
See this blog post for info about using IsDialogMessage on non dialog windows. See this post series for a great overview about the dialog manager and how to write your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With