0
votes

I'm at a loss on this one, not really even sure what code to post.

I have a c++ application. The initial window has an edit control, custom control, and menu. When the user presses F5, a new window open with its own message loop. The new window then opens a DialogBox, and is modal as expected.

The odd part is that the DialogBox seems to be hidden behind the 2nd window. I have to alt-tab to the first window, then alt-tab back to the second window to get to the dialog box.

If I cancel out of the DialogBox, the second window is destroyed (as expected), and a MessageBox is shown (as expected), but that message box seems to be hidden behind the first window. Again, I have to alt-tab twice to get the MessageBox to the forefront, and OK out of it.

Does anyone have any ideas what could cause this odd Pop-Under behavior with both the DialogBox and MessageBox?

Thanks!

Code to create the Dialog Box

INT_PTR ip = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AMBIGUOUS), this->hWnd, DlgAmbiguous);

Code for the DlgAmbiguous Proceduels

INT_PTR CALLBACK DlgAmbiguous(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        {
            HWND hStaticTerm = GetDlgItem(hDlg, IDC_TERM);
            SetWindowText(hStaticTerm, lpAmbiguousTerm);

            if (wcscmp(lpAmbiguousTerm, L"canvas") == 0)
            {
                HWND hComboBox = GetDlgItem(hDlg, IDC_MEANING);
                SendMessage(hComboBox, CB_ADDSTRING, NULL, reinterpret_cast<LPARAM>(_T("Program Window")));
                SendMessage(hComboBox, CB_ADDSTRING, NULL, reinterpret_cast<LPARAM>(_T("Region in Program Window")));
            }

            return (INT_PTR)TRUE;
        }
    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK)
        {
            HWND hComboBox = GetDlgItem(hDlg, IDC_MEANING);
            iAmbiguousResult = SendMessage(hComboBox, CB_GETCURSEL, NULL, NULL);
            EndDialog(hDlg, iAmbiguousResult + 100);
            return (iAmbiguousResult == -1) ? FALSE : TRUE;
        }
        else if (LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, DLG_CANCEL);
            return (INT_PTR)FALSE;
        }
        break;
    }
    return (INT_PTR)FALSE;
1
Looks like you use some libraries... providing more information will help your readers...xQuare
Which standard library component provides your "DialogBox"?Kerrek SB
...and here I was thinking you were using the standard FooBarWiz::DialogBox, which has a convenient member function put_in_right_place(). I guess I should have read your code more carefully :-)Kerrek SB
Code showing how you create the dialog box along with its dialog procedure would be helpful. Also, providing tags like windows and winapi are helpful to understand what platform and gui library you are using.Jesse Good
You might want to avoid the [c++] tag in the future when you ask a Windows api question. The inevitable long wtf comment trail tends to scare people away.Hans Passant

1 Answers

1
votes

When you open a window, regardless if it runs on the same thread or not, it makes sense to specify its parent window. This will force new window to appear above its parent. The same applies to the dialog box:

INT_PTR WINAPI DialogBox(
  _In_opt_  HINSTANCE hInstance,
  _In_      LPCTSTR lpTemplate,
  _In_opt_  HWND hWndParent,
  _In_opt_  DLGPROC lpDialogFunc
);

Note the third parameter. Other option to bring your window on top is by calling the SetWindowPos function.