문제

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)4 as the hMenu parameter to CreateWindowEx to 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 like CreateMenu. If the handle is not a valid HMENU window 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 CreateWindowEx returns NULL. Checking return values is advisable, and calling GetLastError when an API call fails is usually quite helpful.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top