我刚刚制作了一个简单的 C++ 窗口并添加了一个菜单,但是当我单击菜单时,特别是“关于”我想显示一个简单的 MessageBox 但我不能 - 因为它没有显示。
LPCWSTR App_Name = TEXT("TestApp");
LPCWSTR App_Title = TEXT("TestTitle");
const int windowWidth = 480;
const int windowHeight = 480;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = App_Name;
wc.lpszMenuName = MAKEINTRESOURCE(MNU_MAINMENU);
wc.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
long screenWidth = rc.right;
long screenHeight = rc.bottom;
HWND hwnd = CreateWindow
(
App_Name,
App_Title,
WS_MINIMIZEBOX | WS_SYSMENU,
(screenWidth / 2) - (windowWidth / 2), (screenHeight / 2)-(windowHeight/2),
windowWidth, windowHeight,
NULL, NULL,
hInstance, NULL
);
ShowWindow(hwnd, iCmdShow );
UpdateWindow(hwnd);
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
和消息框...:
LRESULT CALLBACK WndProc(HWND hwnd,UINT message, WPARAM wparam, LPARAM lparam)
{
switch( message )
{
case WM_COMMAND:
id = LOWORD(wparam);
event = LOWORD(wparam);
switch(id)
{
case MNU_HELP_ABOUT:
MessageBox(NULL, TEXT("TEXT"), TEXT("TITLE"), MB_OK | MB_ICONINFORMATION);
break;
}
break;
}
}
菜单有效,因为我添加了一个 Quit 等,所以我知道它会响应菜单上的点击,但是当我点击 About 按钮时,您会听到弹出声音,但没有显示 MessageBox。
有任何想法吗?