我一直试图让我的程序在选择不同的菜单项时显示不同的无模式对话框。到目前为止,我只在显示 1 但我无法让它工作。
当我运行我的代码时,我可以看到主窗口失去焦点,但没有显示关于对话框。
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;
}
这是我的关于框的代码:
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;
}
然后我在 WndProc 中调用
case IDM_ABOUT:
CreateDialog(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
对于粘贴如此大的代码部分,我深表歉意,但我不知道问题到底出在哪里。
对此的任何帮助都会很棒!