Sil
Sil

Reputation: 252

Why this Windows message loop does not handle shorcut/tab keys?

There is a following loop in the code used during lengthy processing:

MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

(can be just added to dialog as an action to button click to demonstrate the issue). During this loop, the dialog is drawn correctly and reacts to almost everything, except for when I press for example ALT to show hot keys underlines, for example O underlined:

enter image description here

It also ignores TAB key used to switch between the controls. Is there something missing in the loop to make this functionality work? I've tried also look for WM_COMMAND in WindowProc which corresponds to pressing of the particular button through key O, and in case of the above loop, WM_COMMAND is never passed in... If I click by mouse, or I remove the custom loop, the WM_COMMAND is generated.

How to make this behavior work with custom loop? Please note that this is just a demonstration example, in the real code it does more (disables the button that lead to this action and possible recursion), but the problem is the same, somewhere in it is similar loop which ignores these tab/alt keys.

Upvotes: 2

Views: 99

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37202

Those features are implemented by IsDialogMessage() which you're not calling.

MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
    if (!IsDialogMessage(hwndDlg, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

Upvotes: 6

Related Questions