I have a problem. I wanted to document my tool development, so instead of mspaint-ing a date on top of screenshot, I wanted to make the window name carry the date and time data. But instead of the string I've got only chinese characters.
Here is my code where I want to assign the string to CreateWindowEx():
char *wndName = "Asphyx V0.01 (Build Date: " __DATE__ " " __TIME__ ")\0";
hWnd = CreateWindowEx(NULL,
L"WindowClass",
(LPCWSTR)wndName,
WS_OVERLAPPEDWINDOW,
300,
300,
wr.right - wr.left,
wr.bottom - wr.top,
NULL,
NULL,
hInstance,
NULL);
EDIT: Guys, I appreciate your answers, but all of them gives me this
Error 29 error C2308: concatenating mismatched strings
and the only somewhat working stuff was a yet deleted answer, but it gave me this:
he used this code:
char title[256];
sprintf(title, "Asphyx V0.01 (Build Date: %s - %s)", __DATE__, __TIME__);
hWnd = CreateWindowEx(NULL,
L"WindowClass",
title,
WS_OVERLAPPEDWINDOW,
300,
300,
wr.right - wr.left,
wr.bottom - wr.top,
NULL,
NULL,
hInstance,
NULL);
According to the standard if one of the strings has an encoding prefix, the rest of the string that don't, will be treated as having the same prefix.
This is not the case with Visual Studio. It is a bug.
You need to use a wide string and prefix every string literal with L
including the macros:
#define WSTR2( s ) L##s
#define WSTR( s ) WSTR2( s )
wchar_t *wndName = L"Asphyx V0.01" WSTR(__DATE__) L" " WSTR(__TIME__) L")";