How to navigate between controls in a Window by TAB key?

I created a window by calling CreateWindow, and put 2 edit controls on it. The edit controls had WS_TABSTOP style, which was enabled. I could change its text, but navigation between controls by TAB key did not work.

I put this code in my message loop:

MSG msg;
while ( GetMessage( &msg, NULL, 0, 0 ) )
{
    if ( !msg.hwnd || !IsDialogMessage( msg.hwnd, &msg ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }
}

Unfortunately, navigating by TAB did not work, edit controls didn't edit, and the only thing happened by pressing TAB was the selection of the text of first control. Can anybody help me?

Upvotes: 2

Views: 972

Answers (2)

Raymond Chen
Raymond Chen

Reputation: 45172

The window handle you pass to IsDialogMessage is the dialog-like window you want to navigate through. You are passing the window that received the message, which is probably the edit control, not the top-level window.

Upvotes: 5

Jerry Coffin
Jerry Coffin

Reputation: 490583

You have two basic choices: either put the controls into an actual dialog (which you'll invoke with DialogBox (or one of its close relatives like DialogBoxEx), or else handle the tabbing yourself.

In the latter case, you need to react when a tab is entered, and set the focus to the other control. Offhand, I don't remember whether you can handle this via WM_NOTIFY, or if you'll have to subclass the controls.

Upvotes: 0

Related Questions