錯誤信息:
error C2440: “=”: 無法從“const char [15]”轉換為“LPCWSTR”
error C2664: “CreateWindowExW”: 不能將參數 2 從“const char [15]”轉換為“LPCWSTR”
專案屬性 → Character Set 設置為 **Use Unicode Character Set**。此模式下:
TCHAR 映射為 wchar_t。LPCWSTR 即 const wchar_t*。"abc" 類型為 const char*,無法隱式轉換。wc.lpszClassName = L"window窗口創建";CreateWindowExW(..., L"window窗口創建", ...)wc.lpszClassName = TEXT("window窗口創建");L"...",MBCS 下為 "..."。TextOutW(hdc, 10, 20, L"哈哈,windows編程創建的窗口!", 28);
TEXT() 或 L""。sizeof(TCHAR) 替代硬編碼 1/2,_countof 計算字符數而非字節數。