RichardC
June 3rd, 2008, 01:38 PM
I have a single line rich edit control for entering commands which is activated by pressing the return key. The return key is caught in the window procedure for the command box:
LRESULT CALLBACK commandBoxSubClassProc(HWND hCmdWnd, WORD mMsg, WPARAM wParam, LONG lParam)
{
switch (mMsg)
{
case WM_GETDLGCODE :
return DLGC_WANTALLKEYS;
case WM_CHAR :
if (wParam == VK_RETURN)
return 0;
break;
case WM_KEYDOWN :
return pI->m_pbcCommandBox->processCmdKeys(hCmdWnd, mMsg, wParam, lParam);
}
return CallWindowProc(g_pOldCommandEditProc, hCmdWnd, mMsg, wParam, lParam);
}
The processCommandKeys() function starts as follows:
LRESULT CBoxCommand::processCmdKeys(HWND hCmdWnd, WORD & rmMsg, WPARAM & rwParam, LONG & rlParam)
{
long dwReturn = 0L;
int iCommandLen = static_cast<int>(SendMessage(hCmdWnd, WM_GETTEXTLENGTH, 0, 0));
char *szCommand = new char[iCommandLen+1];
szCommand[0] = iCommandLen+1;
int iCharRead = SendMessage(hCmdWnd, EM_GETLINE, 0, LPARAM(szCommand));
szCommand[iCommandLen] = '\0';
...
This code normally works fine, however I recently installed some virtual desktop software called "enable Virtual Desktop" and when this is running the above code stops working. The WM_GETTEXTLENGTH still returns the correct string length but the EM_GETLINE message always returns 0 characters read. If I exit the virtual desktop software it starts working again.
GetLastError() returns 0 so that's no help and the only thing I can think is that it has something to do with unicode. The documentation for EM_GETLIN says:
Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters.
It may be changing to unicode when he virtual desktop software is running, possibly because I have Japanese language support installed, in which case the above code won't work. Of course it could be something else entirely.
I don't have a clue how to fix this because I'm rubbish at programming and whenever I use the Windows API everything seems to go wrong. Can anybody suggest why this isn't working when the virtual desktop software is running and what I should do to fix it?
Thanks for any help you can offer.
LRESULT CALLBACK commandBoxSubClassProc(HWND hCmdWnd, WORD mMsg, WPARAM wParam, LONG lParam)
{
switch (mMsg)
{
case WM_GETDLGCODE :
return DLGC_WANTALLKEYS;
case WM_CHAR :
if (wParam == VK_RETURN)
return 0;
break;
case WM_KEYDOWN :
return pI->m_pbcCommandBox->processCmdKeys(hCmdWnd, mMsg, wParam, lParam);
}
return CallWindowProc(g_pOldCommandEditProc, hCmdWnd, mMsg, wParam, lParam);
}
The processCommandKeys() function starts as follows:
LRESULT CBoxCommand::processCmdKeys(HWND hCmdWnd, WORD & rmMsg, WPARAM & rwParam, LONG & rlParam)
{
long dwReturn = 0L;
int iCommandLen = static_cast<int>(SendMessage(hCmdWnd, WM_GETTEXTLENGTH, 0, 0));
char *szCommand = new char[iCommandLen+1];
szCommand[0] = iCommandLen+1;
int iCharRead = SendMessage(hCmdWnd, EM_GETLINE, 0, LPARAM(szCommand));
szCommand[iCommandLen] = '\0';
...
This code normally works fine, however I recently installed some virtual desktop software called "enable Virtual Desktop" and when this is running the above code stops working. The WM_GETTEXTLENGTH still returns the correct string length but the EM_GETLINE message always returns 0 characters read. If I exit the virtual desktop software it starts working again.
GetLastError() returns 0 so that's no help and the only thing I can think is that it has something to do with unicode. The documentation for EM_GETLIN says:
Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters.
It may be changing to unicode when he virtual desktop software is running, possibly because I have Japanese language support installed, in which case the above code won't work. Of course it could be something else entirely.
I don't have a clue how to fix this because I'm rubbish at programming and whenever I use the Windows API everything seems to go wrong. Can anybody suggest why this isn't working when the virtual desktop software is running and what I should do to fix it?
Thanks for any help you can offer.