Thread: Retrieving the text from an edit box

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    32

    Retrieving the text from an edit box

    Hi ~

    I'm trying to use WM_GETTEXT to retrieve the contents of an edit box, "EditTitle".
    The syntax for WM_GETTEXT is as follows:

    Code:
    WM_GETTEXT wParam = (WPARAM) cchTextMax; 
      lParam = (LPARAM) lpszText;
    , where cchTextMax is the amount of characters to be copied, and lpszText is a 'Long pointer to the buffer that is to receive the text.' The problem is that I am not sure how to use this message inside a function call, i.e.

    Code:
    SaveTitle(WM_GETTEXT etc)
    Please can someone who has a lot more programming experience than I help me out?

    Thanks;

    ~ Chris Howarth

  2. #2
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Do you actually see WM_GETTEXT in msdn?
    lResult = SendMessage(
    // returns LRESULT in lResult
    (HWND) hWndControl,
    // handle to destination control
    (UINT) WM_GETTEXT,
    // message ID
    (WPARAM) wParam,
    // = (WPARAM) () wParam;
    (LPARAM) lParam
    // = (LPARAM) () lParam;

    );
    You need SendMessage
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    Oh yes, I forgot to include that in my code snippet... What i dont get is the Long Pointer to the buffer that is to receive the text. How do I just get it to return a value? :S

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    try....

    Code:
    char            szTitle[256]={'\0'};
    
    GetDlgItemText(hDialog, Edit_Title, szTitle, 255 );
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by novacain View Post
    try....

    Code:
    char            szTitle[256]={'\0'};
    
    GetDlgItemText(hDialog, Edit_Title, szTitle, 255 );
    Including the null char, so its 256

    Code:
    GetDlgItemText(hDialog, Edit_Title, szTitle, sizeof(szTitle));

  6. #6
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    OK thanks. I'll try that.

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    Code:
    char  szTitle[256]={'\0'};
            GetDlgItemText(hwnd, EditTitle, szTitle, sizeof(szTitle));
    I unfortunately get these errors:
    Code:
    invalid conversion from 'HWND__*' to 'int'
    initialising argument 2 of 'UINT GetDlgItemTextA(HWND__*, int, CHAR*, int)'
    What am I doing wrong?

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    [Forger's example]

    Code:
        int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
        if(len > 0)
        {
            int i;
            char* buf;
    
            buf = (char*)GlobalAlloc(GPTR, len + 1);
            GetDlgItemText(hwnd, IDC_TEXT, buf, len + 1);
    
            //... do stuff with text ...
    
            GlobalFree((HANDLE)buf);
        }

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    The 2nd arg isn't a HWND its the control's resource ID, ie 4000

  10. #10
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    We can sit here and throw suggestive functions at him all day, but garaunteed he figures this out, he'll just be back tomorrow asking wtf a HWND is. Chrishowarth, before you just decide to "jump into" winapi programming, first learn the basics, i.e. how the Message Queue works and what SendMessage actually does. I'd suggest theForger's winapi tut, you can find it in the stickies at the top of this forum.

  11. #11
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    Chrishowarth, before you just decide to "jump into" winapi programming, first learn the basics, i.e. how the Message Queue works and what SendMessage actually does. I'd suggest theForger's winapi tut, you can find it in the stickies at the top of this forum.
    I've almost finished my app, and I'm learning more from creating this than I did with the tutorials. Of course I read the tutorials, but making a program is helping me understand it.

    Thanks! ; my code does compile now with that function. I'm not quite sure what it returns though, because if i try to use the variable I assign to it I get the error "Invalid convertion from 'UINT' to 'char*'
    Last edited by chrishowarth; 05-11-2007 at 09:54 AM.

  12. #12
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Look at MSDN then!

  13. #13
    Registered User
    Join Date
    Mar 2007
    Posts
    32
    It works!!! Thankyou all so much Sorry I am a bit slow.

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>"Invalid convertion from 'UINT' to 'char*'

    If you get this on a resource ID param then use the macro

    MAKEINTRESOURCE()
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 12:03 AM
  4. Edit Box Questions PT. II
    By Quantrizi in forum Windows Programming
    Replies: 16
    Last Post: 08-12-2003, 10:42 PM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM