开发者

how to set the tab order for the UI controls in win 32?

hello all I have a small dialog which I created dynamically, which has a textbox and a button..if the user presses the TAB key it has to switch between the two control(textbox and button)...I tried using SetwindowPos...but it doesnt seem to solve my problem...please give me a solution for this..in the below code..I also tried to include the mainwindow in the taborder..still it doesnt work

//dialog creation

HWND dialogHandle = CreateWindowEx(0,WC_DIALOG,L"Security Alert",WS_OVERLAPPEDWINDOW|WS_VISIBLE,600,300,280,160,NULL,NULL,NULL,NULL);

//create textboxcontrol within the dialog
    HWND textBoxHandle = CreateWindowEx(WS_EX_CLIENTEDGE,L"EDIT",L"",WS_CHILD|WS_VISIBLE |ES_PASSWORD | WS_TABSTOP,123,48,110,25,dialogHandle,(HMENU)IDD_TEXTBOX,NULL,NULL);

    //create but开发者_如何学运维ton
    HWND buttonHandle  = CreateWindowEx(NULL,L"Button",L"OK",WS_CHILD|WS_VISIBLE| WS_TABSTOP,151,85,85,25,dialogHandle,(HMENU)ID_PASSWORD_OK,NULL,NULL);

//setwindowpos

SetWindowPos(NULL,textBoxHandle,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
SetWindowPos(textBoxHandle,buttonHandle,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);


In your message loop, you need to call IsDialogMessage for keyboard events (such as the tab key) to be processed by the dialog box. This is described here.

Here is an example:

while (GetMessage(&msg, NULL, 0, 0) > 0) {
    if (!IsDialogMessage(dialogHandle, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜