0

I have been trying to get my program to display different modeless dialog boxes when different menu items are selected. So far I am only working on displaying 1 but I am unable to get this working.

When I run my code I can see the main window losing focus but the about dialog box is not being displayed.

HWND g_hToolbar = NULL;
HWND hDlgCurrent = NULL;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR    lpCmdLine,
int       nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

MSG msg;
HACCEL hAccelTable;

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_GUIAPP, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
    return FALSE;
}

while(GetMessage(&msg, NULL, 0, 0) > 0)
{
    if(!IsDialogMessage(g_hToolbar, &msg))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
return (int) msg.wParam;
}

Here is the code for my about box:

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{

UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_CREATE:
    g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUTBOX),
        hDlg, ToolDlgProc
        );
    if(g_hToolbar != NULL)
    {
        ShowWindow(g_hToolbar, SW_SHOW);
    }
case WM_INITDIALOG:
    return (INT_PTR)TRUE;

case WM_ACTIVATE:
    if (0 == wParam)             // becoming inactive
        hDlgCurrent = NULL;
    else                         // becoming active
        hDlgCurrent = hDlg;
    return FALSE;

case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDOK)
    {
        EndDialog(hDlg, LOWORD(wParam));
        return (INT_PTR)TRUE;
    }
    break;
}
return (INT_PTR)FALSE;
}

Then my Call in WndProc

    case IDM_ABOUT:
        CreateDialog(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);        
        break;

I apologize for pasting such large sections of code in but I am unaware as to where exactly the problem is.

Any help on this would be great!

Daniel Flannery
  • 1,166
  • 8
  • 23
  • 51
  • The code creating modal dialog is missing. And apparently that code is what you're asking about. Anyway, if you code in C++ instead of C things would become much more clear and safe. Be aware that `tWinMain` monstrosity is neither standard C, nor standard C++, and that it serves no technical purpose. It is only Microsoft obfuscation, so, use a standard `main`. Also, it helps to not use global variables. And don't use C style casts, in general. – Cheers and hth. - Alf Apr 23 '12 at 13:15
  • Why does your `WM_CREATE` handler try and create the dialog again? – Deanna Apr 23 '12 at 13:18
  • I have solved the Issue. There was no need to have g_hToolbar creating dialogs too. I just moved `ShowWindow(g_hToolbar, SW_SHOW);` to `WM_INITDIALOG` and its working for me. – Daniel Flannery Apr 23 '12 at 13:21

1 Answers1

0

This issue has been solved.

The solution is contained in the comments.

Daniel Flannery
  • 1,166
  • 8
  • 23
  • 51