C ++使用WINAPI(无MFC)启动几个无模式对话框 [英] C++ Starting several modeless dialogs using WINAPI ( no MFC )
问题描述
当选择不同的菜单项时,我一直试图让我的程序显示不同的无模式对话框。到目前为止,我只工作在显示1,但我无法得到这个工作。
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;
}
然后我在WndProc中的呼叫
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!
推荐答案
问题已解决。
解决方案包含在注释中。
The solution is contained in the comments.
这篇关于C ++使用WINAPI(无MFC)启动几个无模式对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!