0

So I tried to put together a window, but when I needed to name the window I told me. (Error: argument of type “const char*” is incompatible of type “LPCWSTR”) Programming for the CreateWindow method is underneath. Error should be in line 2.


hwnd = CreateWindow(
    "Engine_Winter_Name",
    "Winter Engine",
    WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
    GetSystemMetrics(SM_CXSCREEN)/2 - WIDTH/2,
    GetSystemMetrics(SM_CYSCREEN)/2 - HEIGHT/2,
    WIDTH,
    HEIGHT,
    (HWND)NULL,
    (HMENU)NULL,
    hInstance,
    (LPVOID*)NULL);

if (!hwnd)
    return false;

ShowWindow(hwnd, nCmdShow);

return true;

All help is more than welcome! Thanks in advance.

0

2 Answers 2

0

You need a wide string. Prefix your strings with L.

hwnd = CreateWindow(
    L"Engine_Winter_Name",
    L"Winter Engine",
0

You're compiling with UNICODE defined, which means that e.g. the CreateWindow macro maps to CreateWindowW, which expects wide character (wchar_t-based) arguments:

hwnd = CreateWindow(
    L"Engine_Winter_Name",
    L"Winter Engine",
    WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION,
    GetSystemMetrics(SM_CXSCREEN)/2 - WIDTH/2,
    GetSystemMetrics(SM_CYSCREEN)/2 - HEIGHT/2,
    WIDTH,
    HEIGHT,
    HWND(),
    HMENU(),
    hInstance,
    nullptr);

if (!hwnd)
    return false;

ShowWindow(hwnd, nCmdShow);

For modern Windows desktop programming it's generally best to use the Unicode based API, as you're doing.

Not the answer you're looking for? Browse other questions tagged or ask your own question.