Take the 2-minute tour ×

My issue is that I am trying to create a Opengl/Win32 application and I am unable to keep my dialog box open. It literally flashes as if someone pressed cancel on it RIGHT when it opened. I've looked around google and found a few others with this issue, but none of the solutions they posted have helped me, so I turn to the StackOverflow community!

Initially, I wrote code for the Dialog Procedure...

    ShowWindow(hWndDlg, SW_SHOW); // These were added to get the window to show up
    UpdateWindow(hWndDlg); // even if the chance was small.
        return true;

    case WM_COMMAND:
        case IDOK:
            EndDialog(hWndDlg, 0);
            return TRUE;

    return FALSE;

I then wrote the actual code to display the box.

void DisplayLoginBox()
    LoginDlgHwnd = NULL;
    LoginDlgHwnd = (HWND)DialogBox(GetModuleHandle(NULL), 

    if(LoginDlgHwnd == NULL)
        MessageBox(NULL, NULL, NULL, MB_OK);

app.GetHandle() returns a hwnd of the main program. This function works properly. and LoginDlgHwnd is a global variable.

The actual dialog is created and included properly as well. Do you have any ideas? -Celestialkey

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted
  • DialogBox does not return a hwnd, the function does not return until the dialog is closed, if you want a modeless dialog and a handle, use CreateDialog
  • The DLGPROC DialogBox parameter should not require a cast, change LoginDlgProc' LRESULT to INT_PTR
  • MessageBox(NULL, NULL, NULL, MB_OK); will not display anything, it needs text in the 2nd parameter

It is hard to say why the dialog does not stay open, but you should check the return value of DialogBox, if it is 0, the parent hwnd is invalid, if it is -1, call GetLastError() to get more info. One thing you could try is to remove all controls in the LOGIN_DIALOG dialog template (If you used common controls, but did not call InitCommonControls, the dialog would not work etc)

share|improve this answer
As a side note, the MessageBox was just testing to see if it was a NULL handle. No reason for text since it was just to throw a warning to me quickly on testing. Your solutions fix the issue though. –  Justin Sterling Sep 30 '10 at 17:35
add comment

Your Answer


