简体   繁体   English

C ++使用WINAPI启动多个无模式对话框(无MFC)

[英]C++ Starting several modeless dialogs using WINAPI ( no MFC )

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. 到目前为止,我只显示1,但是无法正常工作。

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 然后我在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! 任何帮助都会很棒!

This issue has been solved. 此问题已得到解决。

The solution is contained in the comments. 解决方案包含在注释中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM