CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2010
    Posts
    76

    Get text from textbox

    Does anyone know how to get text from a text box with out it displaying odd symbols with chars?

    Thanks


    I need to get the text but everything online keeps telling me to use GetWindowText which needs a char which ends up with odd symbols in it such as a smiley face and stuff.

    I need to get the text as a string not a char.

    Thanks again

  2. #2
    Join Date
    Jun 2005
    Posts
    315

    Re: Get text from textbox

    GetWindowText which needs a char
    Code:
    int GetWindowText(
      __in   HWND hWnd,
      __out  LPTSTR lpString,
      __in   int nMaxCount
    );
    I guess I'm not understanding what you wrote as I don't see where the GetWindowText() function needs a char? Might you be having some kind of UNICODE problems?

  3. #3
    Join Date
    Apr 2010
    Posts
    20

    Re: Get text from textbox

    Code:
    void GetTextAndDoSomething(HWND hWnd)
    {
        // get the length of the text
        const int nTextLength = ::GetWindowTextLength(hWnd);
    
        // allocate a buffer for the text
        char * pData = new char[nTextLength + 1];
    
        // Get the text
        ::GetWindowTextA(hWnd,pData,nTextLength + 1);
    
        // Do something with this text
        ::MessageBoxA(0,pData,"This is the text!",MB_OK);
    
        // free the buffer
        delete [] pData;
    }

  4. #4
    Join Date
    Jan 2010
    Posts
    76

    Re: Get text from textbox

    thanks you two you helped me out

    thanks again!

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