我使用MSVC ++向导创建了一个win32应用程序。我添加了一个新的菜单资源并添加了典型的“文件” - >“退出”等。然后我将它添加到msvc ++中属性下的主对话框中。当我运行表单时,它显示表单上的菜单,但如果我单击文件,它甚至不执行悬停,它不会显示退出的弹出窗口。它几乎就像是残疾人。我真的不认为我需要添加任何代码。任何帮助表示赞赏。感谢。
#include "stdafx.h"
#define MAX_LOADSTRING 100
struct _globals {
HINSTANCE hInst;
HWND hWnd;
} g;
LRESULT CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
InitCommonControls();
g.hInst = hInstance;
g.hWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, (DLGPROC)DialogProc);
if (g.hWnd == NULL) {
GetLastError();
return FALSE;
}
ShowWindow(g.hWnd, nCmdShow);
UpdateWindow(g.hWnd);
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_ACCELLS));
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
if (TranslateAccelerator(g.hWnd, hAccelTable, &msg))
continue;
if (IsDialogMessage(g.hWnd, &msg))
continue;
// process message
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
答案 0 :(得分:0)
您的DialogProc功能看起来更像是窗口过程而不是对话框过程。与窗口过程不同,dalog过程不返回LRESULT值,它们返回BOOL值,并且它们不调用DefWindowProc。还有其他一些差异。