Thread: GetWindowText doesn't return the text

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    GetWindowText doesn't return the text

    I have made a textbox and there is text in it, but when I use GetWindowText(...) to get the text it returns a uni code string full on nonsence stuff.

    Here is the string it returns:

    ‹ÿU‹ì‹MVè´Ôýÿ‹ð…öt8‹U ;è


    No matter the text I put it always returns that. Why and how can I get the real text?

    And if I use SendMessage(hwnd_of_textbox, WM_GETTEXT, (WPARAM)10, (LPARAM)text)

    it gives and "sorry application had to close" error.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Are you certain that your HWND value is valid?

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I made the textbox my self so yes, cause the text will change if I send a change message.

  4. #4
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    maybe post the part of the code where you have to grab the text..
    * 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.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Code:
                	GetWindowText(recvbox, text, 10);
                	//SendMessage(recvbox, WM_GETTEXT, (WPARAM)10, (LPARAM)text);  //Gives an error
                	SendMessage(recvbox, WM_SETTEXT, NULL, (LPARAM)text);
    There is the code. I put the text from the recvbox back into as a test, wich still gives that messed up string.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Is text large enough to hold 10 characters? What does GetWindowText return? If it's zero, what does GetLastError return afterwards?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    Umm text is declared as fallows:

    LPSTR text;

    The error part I will check when I get home from school.

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Umm text is declared as fallows:

    LPSTR text;
    That's your problem. You need to declare it as:
    Code:
    TCHAR text[10];

  9. #9
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    bithub, it would be more compatible if it was:
    Code:
    char text[10];
    Instead of:
    Code:
    TCHAR text[10];

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Or if you really want it in a LPSTR format, just do this:
    Code:
    char textT[10];
    GetWindowText(recvbox, textT, 10);
    LPSTR text = textT;


    BTW: I tried compiling it the way you had it,
    ad I got errors. How come when you did it, it did it.
    Last edited by Queatrix; 09-23-2005 at 02:46 PM.

  11. #11
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I am using visual c++ toolkit 2003 compiler?

    I noticed a huge differnce in ahh what is it GNU... no well what ever dev-c++ uses and toolkit 2003.

  12. #12
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    I am using visual c++ toolkit 2003 compiler?

    I noticed a huge differnce in ahh what is it GNU... no well what ever dev-c++ uses and toolkit 2003.

  13. #13
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Hunter, you have dial-up don't you?

  14. #14
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    ahh no... dsl... what does that have to do with this?

    The speed is sorta unsure but I download at 160kb a second.

  15. #15
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Nothing. I just noticed that you clicked the "Post Reply" button twice. The reason I thought you had dial-up is because some times people tend to push it twice thinking it didn't go though the first time because the page didn't load fast enough.

    I wish I had DSL.
    (My speed is only 63kbps.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is it ok like that?
    By ExDHaos in forum C++ Programming
    Replies: 8
    Last Post: 05-23-2009, 09:02 AM
  2. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  3. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  4. Memory leak - need help finding
    By ChadJohnson in forum C++ Programming
    Replies: 8
    Last Post: 04-06-2005, 07:26 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM