views:

27

answers:

3

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 message 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

A: 

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.

vulkanino
Thanks for the info. I actually came across this in the MSDN before and it seems to suggest that what I am doing is correct. My parent pane has the WS_EX_CONTROLPARENT style set and my text boxes have WS_TABSTOP set but still nothing.
A: 

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.

Alex Farber
I just tried the technique in the article and it hasn't made a difference unfortunately. Is this the correct way to be loading dialog resources or is there a better way?
+1  A: 
if( !IsDialogMessage(0, &msg) )

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

Hans Passant