I have a pMsg->wParam from a WM_KEYDOWN message, and I want to convert it into a CString. How can I do that?
I have tried the following code:
TCHAR ch[2];
ch[0] = pMsg->wParam;
ch[1] = _T('\0');
CString ss(ch);
but it does not work for high ASCII characters.
The problem is that
wParamcontains a pointer to an array of characters. It is not a single character, so you can’t create the string yourself by assigning it toch[0]as you’re trying to do here.The solution turns out to be a lot easier than you probably expected. The
CStringclass has a constructor that takes a pointer to a character array, which is precisely what you have inwParam.(Actually, it has a bunch of constructors, one for pretty much everything you’ll ever need…)
So all you have to do is:
The constructor will take care of the rest, copying the string pointed to by
wParaminto thesstype.