In addition to the main window, I'm trying to create another top level window. The problem is that when I'm setting the second window's hMenu parameter to a non-NULL value, it doesn't show up.
e.g:
This window shows up (hMenu == 0)
case IDC_BUTTON_SEND_COMMAND:
{
CreateWindowExW(NULL,
L"CommandWindow", L"Send Command",
WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
100, 100, 600, 400,
NULL,
(HMENU)0,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
break;
}
This window doesn't show up (hMenu == 4)
case IDC_BUTTON_SEND_COMMAND:
{
CreateWindowExW(NULL,
L"CommandWindow", L"Send Command",
WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
100, 100, 600, 400,
NULL,
(HMENU)4,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
break;
}
I'm using Windows 7.
Passing
(HMENU)4as thehMenuparameter toCreateWindowExto create a top level window tells the system to attach a menu to it. This menu has the menu handle 4. A menu handle (HMENU) is returned from functions likeCreateMenu. If the handle is not a validHMENUwindow creation fails.Your observation, that the window doesn't show up is misleading yourself into believing that the window actually exists. The window doesn't exist, and
CreateWindowExreturnsNULL. Checking return values is advisable, and callingGetLastErrorwhen an API call fails is usually quite helpful.