I’ve just made a simple C++ Window and added a menu, but when I click on the menu, specifally “About” i want to show a simply MessageBox but I can’t – because it doesn’t show.
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;
}
and the MessageBox…:
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;
}
}
Menu works, cause I’ve added a Quit and such so I know it responds to the clicks on the menu but when I click the About button you hear the popup sound but there’s no MessageBox showing.
Any ideas?
I figured it out, somehow. Problem was because I haven’t done anything in WM_CREATE, or that that “nothing” was on the form – White background, or something. As soon as I started adding controls (buttons) to the Window it suddenly appeared where it didn’t before. Just weird…