Cit*_*rus 1 c++ winapi direct3d createwindowex
我有个问题。我想记录我的工具开发,所以我想让窗口名称带有日期和时间数据,而不是在屏幕截图顶部使用 mspaint 来显示日期。但是我只有中文字符而不是字符串。

这是我想将字符串分配给 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);
Run Code Online (Sandbox Code Playgroud)
编辑:伙计们,我很欣赏你的回答,但他们都给了我这个
Error 29 error C2308: concatenating mismatched strings
Run Code Online (Sandbox Code Playgroud)
唯一有点工作的东西是一个尚未删除的答案,但它给了我这个:

他使用了这个代码:
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);
Run Code Online (Sandbox Code Playgroud)
根据标准,如果字符串之一具有编码前缀,则字符串的其余部分没有,将被视为具有相同的前缀。
Visual Studio 不是这种情况。这是一个错误。
您需要使用宽字符串并在每个字符串文字前加上L宏:
#define WSTR2( s ) L##s
#define WSTR( s ) WSTR2( s )
wchar_t *wndName = L"Asphyx V0.01" WSTR(__DATE__) L" " WSTR(__TIME__) L")";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
925 次 |
| 最近记录: |