简体   繁体   中英

setting text in edit box using variable

I got simple function which is defined like this:

void addEndText(HWND hEdit, LPCWSTR newText)
{
int TextLen = SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);
SendMessage(hEdit, EM_SETSEL, (WPARAM)TextLen, (LPARAM)TextLen);
SendMessage(hEdit, EM_REPLACESEL, FALSE, (LPARAM)newText);
}

when I call it in this way:

 addEndText(editHandler1, L"TEST TEXT")

everything seems to be good and work properly. But when i just do this in this way:

addEndText(editHandler1, (LPCWSTR)buff)

where buff is char array, in my edit box appears weird characters instead of what was in buff. I know this is because of coding schema. But I dont know how can I make it working. Thanks for any respond

Assuming buff is a char[] or char* , you cannot simply type-cast it to a LPCWSTR (ie const wchar_t* ). You have to convert its data from char to wchar_t , such as with MultiByteToWideChar() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM