开发者

Making TAB key work on Windows dialog

开发者 https://www.devze.com 2023-01-18 09:26 出处:网络
I\'m working on a Windows project with a simple dialog created with CreateWindowEx() it contains multiple panes loaded with CreateDialog() to load the layout from a resource file. On the child panes t

I'm working on a Windows project with a simple dialog created with CreateWindowEx() it contains multiple panes loaded with CreateDialog() to load the layout from a resource file. On the child panes there are a number of controls including text boxes and buttons which I would like to use TAB to navigate around but all I get is the Windows 'bing' telling me that the key does not do anything. My mess开发者_如何转开发age loop looks like this:

while( PeekMessage(&msg, 0, 0, 0, PM_REMOVE) )
{
    if( !IsDialogMessage(0, &msg) )
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

And each control window has WS_TABSTOP set in the style as well as the owner pane having WS_EX_CONTROLPARENT set.

Is there anything else I need to do to make the tab key work?

Thanks, J


Try this:

http://support.microsoft.com/kb/71450 (How To Use One IsDialogMessage() Call for Many Modeless Dialogs)

You panes are modeless dialogs, and IsDialogMessage is responsible for handling Tab keys. I hope that this article exactly matches your case.


The WS_TABSTOP Style The WS_TABSTOP style specifies the controls to which the user can move by pressing the TAB key or SHIFT+TAB keys.

When the user presses TAB or SHIFT+TAB, the system first determines whether these keys are processed by the control that currently has the input focus. It sends the control a WM_GETDLGCODE message, and if the control returns DLGC_WANTTAB, the system passes the keys to the control. Otherwise, the system uses the GetNextDlgTabItem function to locate the next control that is visible, not disabled, and that has the WS_TABSTOP style. The search starts with the control currently having the input focus and proceeds in the order in which the controls were createdthat is, the order in which they are defined in the dialog box template. When the system locates a control having the required characteristics, the system moves the input focus to it.

If the search for the next control with the WS_TABSTOP style encounters a window with the WS_EX_CONTROLPARENT style, the system recursively searches the window's children.

An application can also use GetNextDlgTabItem to locate controls having the WS_TABSTOP style. The function retrieves the window handle of the next or previous control having the WS_TABSTOP style without moving the input focus.

Source: MSDN.


if( !IsDialogMessage(0, &msg) )

The first argument should not be NULL, it must be the handle of a dialog. Painful here of course.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号