CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    10

    Post Problem Reading Text From Edit Control

    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:

    Code:
    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:

    Code:
    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.

  2. #2

    Re: Problem Reading Text From Edit Control


  3. #3
    Join Date
    Aug 2007
    Posts
    10

    Re: Problem Reading Text From Edit Control

    Thanks for the reply. EM_STREAMOUT works great even when the virtual desktop software is running. It seems like a rather roundabout way to read a few characters but as long as it works I’m happy.

    I don’t really understand why EM_GETLINE doesn’t work when the virtual desktop software is running but then there’s a lot I don’t understand so one more thing won’t do me any harm

    Thanks again for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured