我需要从 转换LPTSTR
为LPCWSTR
。我需要这个,因为我LPTSTR
来自GetDlgItemText
,我要喂它ExtTextOut
,它接受LPCWSTR
。
编辑:在传递值之前,GetDlgItemText
我将值存储在std::vector
. 之后我从 中检索值std::vector
,它返回给我一个空/胡言乱语。
对话框:
WORD lineLength = (WORD) SendDlgItemMessage(hwnd,IDC_EDIT1, EM_LINELENGTH, (WPARAM) 0, (LPARAM) 0);
if(lineLength > 0){
TCHAR line[16];
int number = GetDlgItemTextW(hwnd, IDC_EDIT1, line, 16);
HWND parent = (HWND)GetWindowLongPtr(hwnd, GWLP_HWNDPARENT);
LPCWSTR line2(line);
SendMessage(parent, WM_COMMAND, MAKEWPARAM(ADD_COMBO_ITEM,0), (LPARAM)line);
它向父窗口发送一条消息,父窗口将此值添加到向量 ( push_back
)。具有父窗口的类:
std::vector<LPCWSTR> comboItems
这是我用来输出我的值的一个函数ExtTextOut
:
RECT temp;
temp.left = listItemWidth;
temp.right = width;
SetBkColor(hdc, RGB(240,240,260));
LPCWSTR comboName = L"";
for(std::vector<item>::size_type i=0; i != comboItems.size(); i++){
temp.left = listItemWidth;
temp.right = width;
temp.top = (currentlyClicked + 1) * listItemHeight + i * listItemHeight;
temp.bottom = temp.top + listItemHeight;
comboName = comboItems[i];
ExtTextOut(hdc, temp.left+2, temp.top + 1, ETO_OPAQUE,
&temp, comboName, lstrlen(comboName), 0);
DrawEdge(hdc, &temp, EDGE_RAISED, BF_RECT | BF_FLAT | BF_ADJUST);
}