windows_programming_notes.nbk: Home | Index | Next Page: The dialog manager, part 9: Custom accelerators in dialog boxes | Previous Page: The dialog manager, part 7: More subtleties in message loops


 The dialog manager, part 8: Custom navigation in dialog boxes

Previously: The dialog manager, part 7: More subtleties in message loops

Some dialog boxes contain custom navigation that goes beyond what the IsDialogMessage function provides. For example, property sheets use Ctrl+Tab and Ctrl+Shift+Tab to change pages within the property sheet. Remember the core of the dialog loop:

while (<dialog still active> && GetMessage(&msg, NULL, 0, 0, 0)) {
    if (!IsDialogMessage(hdlg, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

(Or the modified version we created in part 7.)

To add custom navigation, just stick it in before calling IsDialogMessage.

while (<dialog still active> && GetMessage(&msg, NULL, 0, 0, 0)) {
    if (msg.message == WM_KEYDOWN && msg.wParam == VK_TAB && GetKeyState(VK_CONTROL) < 0) {
  ... do custom navigation ...
    } 
    else if (!IsDialogMessage(hdlg, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

After retrieving a message, we check whether it was Ctrl+Tab before dispatching it or indeed even before letting IsDialogMessage see it. If so, then treat it as a navigation key.

Note that if you intend to have modeless dialogs controlled by this message loop, then your test needs to be a little more focused, because you don't want to pick off keyboard navigation keys destined for the modeless dialog.

while (<dialog still active> && GetMessage(&msg, NULL, 0, 0, 0)) {
    if ((hdlg == msg.hwnd || IsChild(hdlg, msg.hwnd)) && 
        msg.message == WM_KEYDOWN && msg.wParam == VK_TAB && 
        GetKeyState(VK_CONTROL) < 0) {
            ... do custom navigation ...
        } 
        else if (!IsDialogMessage(hdlg, &msg)) {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
        }
    }
}

Next time, we'll see another way of accomplishing this same task.

Published Thursday, April 07, 2005 5:05 AM by oldnewthing http://blogs.msdn.com/oldnewthing/archive/2005/04/07/406012.aspx


windows_programming_notes.nbk: Home | Index | Next Page: The dialog manager, part 9: Custom accelerators in dialog boxes | Previous Page: The dialog manager, part 7: More subtleties in message loops


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time