簡體   English   中英

winAPI 中 L 前綴(LPCWSTR 類型轉換)的問題

[英]Problem with the L prefix ( LPCWSTR typecast) in winAPI

我是 winAPI 的新手,遇到了一個我似乎無法解決的問題......谷歌也找不到解決方案。

我的程序有幾個大小相似的按鈕,所以我做了一個宏來隱藏所有的混亂。 原來的宏是:

#define _BUTTON(s, x, y, v)    CreateWindowW(L"Button", (L)s, WS_VISIBLE | WS_CHILD, x, y, 75, 25, hWnd, (HMENU)v, 0, 0);

但是,在sL上,無論是否帶有括號,“ L(s) ”都不起作用。 我還嘗試用LPCWSTRWCHAR*_T()等替換L ......編譯器錯誤總是相同的: "L (or LPCWSTR, etc) is not declared in this scope"盡管我認為它應該是.. .

現在我通過使用非 Unicode 解決了這個問題:

#define _BUTTON(s, x, y, v)    CreateWindow("Button", s, WS_VISIBLE | WS_CHILD, x, y, 75, 25, hWnd, (HMENU)v, 0, 0);

但我希望所有的窗口都支持相同的字符......問題出在哪里?

一種方式是 RbMm 提到的,例如:

#define Create_Button(s, x, y, v)     CreateWindowW(L"Button", L##s, WS_VISIBLE | WS_CHILD, x, y, 75, 25, hWnd, (HMENU)v, 0, 0);

另一種方法是使用通用方法:

#define Create_ButtonA(s, x, y, v)    CreateWindowA("Button", s, WS_VISIBLE | WS_CHILD, x, y, 75, 25, hWnd, (HMENU)v, 0, 0);
#define Create_ButtonW(s, x, y, v)    CreateWindowW(L"Button", s, WS_VISIBLE | WS_CHILD, x, y, 75, 25, hWnd, (HMENU)v, 0, 0);
#ifdef _UNICODE
#define Create_Button(s, x, y, v)     Create_ButtonW(s, x, y, v)
#else
#define Create_Button(s, x, y, v)     Create_ButtonA(s, x, y, v)
#endif

用法:

Create_Button(TEXT("name"),10,10,2);
Create_ButtonA("name",10,10,2);
Create_ButtonW(L"name",10,10,2);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM