I used a very minimal Windows Application for testing. The application only uses the "W" versions of Windows API functions to create a UNICODE Window. The Character set property of the project was configured as "Not Set".
Sample for testing -
#include <windows.h>
#include <stdio.h>
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LPCWSTR pwszTitle = L"Sample Title";
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
hInst = hInstance;
WNDCLASSW wc =
{
CS_HREDRAW | CS_VREDRAW, WndProc, 0, 0, hInst, LoadIconW(NULL, MAKEINTRESOURCEW(32512)),
LoadCursorW(NULL, MAKEINTRESOURCEW(32512)), (HBRUSH)(COLOR_WINDOW + 1), NULL, L"WindowClass"
};
if (!RegisterClassW(&wc))
return MessageBoxW(NULL, L"RegisterClassExW failed!", L"Error", MB_ICONERROR | MB_OK);
HWND hWnd = CreateWindowExW(0, wc.lpszClassName, pwszTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL);
if (!hWnd)
return MessageBoxW(NULL, L"CreateWindowExW failed", L"Error", MB_ICONERROR | MB_OK);
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
MSG msg;
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
/*
case WM_NCCREATE:
{
WCHAR szMsg[128];
LPCREATESTRUCTW lpcs = (LPCREATESTRUCTW)lParam;
swprintf_s(szMsg, L"In WM_NCCREATE, Window Class: %s, Window Title: %s\n", lpcs->lpszClass, lpcs->lpszName);
OutputDebugStringW(szMsg);
return TRUE;
}
break;
case WM_CREATE:
{
WCHAR szMsg[128];
LPCREATESTRUCTW lpcs = (LPCREATESTRUCTW)lParam;
swprintf_s(szMsg, L"In WM_CREATE, Window Class: %s, Window Title: %s\n", lpcs->lpszClass, lpcs->lpszName);
OutputDebugStringW(szMsg);
}
break;
*/
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
When the handlers for WM_NCCREATE and WM_CREATE are commented out the window caption is truncated as described by the Questioner. However, I can think of no reason for this to happen!
Spy++ shows that a UNICODE window was created but the UNICODE text passed to CreateWindowExW was truncated anyway!
Then when the WM_NCCREATE and WM_CREATE handlers are uncommented the created window has no caption at all!
And the debug output from the two handlers shows the proper UNICODE text for the Window caption -
I don't understand why passing UNICODE text to a "W" API function for a UNICODE window causes such unexpected results. It doesn't seem to me that the project character set property is relevant in this example.