WS_CHILD对话框上的WS_TABSTOP

时间:2014-01-11 13:44:54

标签: c++ winapi dialog

我正在使用简单的对话框。该对话框是从资源文件创建的。创建对话框WS_CHILD时,一切正常。我可以使用VK_TAB键在项目(编辑框和按钮)之间轻松切换。但是当我尝试将对话框的类型更改为WS_POPUP时,在元素之间切换变得不可能。焦点停留在第一个元素上,当我按下VK_TAB键时,我得到系统警报声(如“ding”)。有什么建议吗?

编译器:gcc 4.6.x

资源示例:

DIALOG_CLIENT_SETTINGS DIALOG 0, 0, 156, 132
STYLE WS_CHILD | WS_VISIBLE | DS_CONTROL // Tab key stucks when change to WS_POPUP
CAPTION "Settings"
FONT 8, "Ms Shell Dlg"
LANGUAGE LANG_NEUTRAL, 0
{
    CONTROL "Account Settings", IDC_GROUPBOX_1, "BUTTON", BS_GROUPBOX | WS_CHILD | WS_VISIBLE, 8, 4, 140, 50
    CONTROL "Login:", IDC_STATIC_1, "STATIC", SS_RIGHT | WS_CHILD | WS_GROUP | WS_VISIBLE, 16, 20, 40, 8
    CONTROL "Password:", IDC_STATIC_2, "STATIC", SS_RIGHT | WS_CHILD | WS_GROUP | WS_VISIBLE, 16, 36, 40, 8
    EDITTEXT IDC_EDIT_1, 60, 18, 80, 12, ES_LEFT | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE, WS_EX_WINDOWEDGE
    EDITTEXT IDC_EDIT_2, 60, 34, 80, 12, ES_LEFT | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE, WS_EX_WINDOWEDGE
    CONTROL "Cancel", IDC_BUTTON_1, "BUTTON", BS_PUSHBUTTON | BS_VCENTER | BS_CENTER | WS_CHILD | WS_TABSTOP | WS_VISIBLE, 98, 112, 50, 14
    CONTROL "Apply", IDC_BUTTON_2, "BUTTON", BS_PUSHBUTTON | BS_VCENTER | BS_CENTER | WS_CHILD | WS_TABSTOP | WS_VISIBLE, 42, 112, 50, 14
}

1 个答案:

答案 0 :(得分:5)

您需要在主消息循环中使用IsDialogMessage,以便对话框可以截获和正确处理消息。您没有解释消息循环的实现方式,这将影响您执行此操作的方式。一种方法是直接编码:

while(GetMessage(&Msg, NULL, 0, 0))
{
    if(!IsDialogMessage(hDialogWnd, &Msg))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
}

如果您为消息循环使用某些框架(如MFC),则可以使用PreTranslateMessage的覆盖来拦截它,如下所示:

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
   if(IsDialogMessage(pMsg))
      return TRUE;
   else 
      return CDialog::PreTranslateMessage(pMsg);
}