Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WS_TABSTOP on WS_CHILD dialogs

Tags:

c++

dialog

winapi

I'm working with simple dialogs. The dialog box is created from the resource file. When creating a dialog box WS_CHILD, everything works fine. I can easily switch between items(edit boxes and buttons) using the VK_TAB key. But when I try to change the type of dialog box to WS_POPUP, switching between the elements becomes impossible. Focus is stuck on the first element and when I push the VK_TAB key I get a system alert sound(like "ding"). Any suggestions?

Compiler : gcc 4.6.x

Resource example:

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
}
like image 649
Viodele Avatar asked Jan 11 '14 13:01

Viodele


1 Answers

You need to use IsDialogMessage in your main message loop so that messages can be intercepted and processed correctly by the dialog. You don't explain how your message loop is implemented, and this will affect how you do this. One way is to code it directly:

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

If you use some framework, such as MFC, for your message loop, then you would intercept it by using an override of PreTranslateMessage, something like this:

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
   if(IsDialogMessage(pMsg))
      return TRUE;
   else 
      return CDialog::PreTranslateMessage(pMsg);
}
like image 109
Roger Rowland Avatar answered Oct 03 '22 12:10

Roger Rowland