getwindowtext() problem

This is a discussion on getwindowtext() problem within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I've got a problem trying to get some text from a edit control. Here's my attempt to get the ...

  1. #1
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18

    getwindowtext() problem

    Hi,

    I've got a problem trying to get some text from a edit control.

    Here's my attempt to get the text from 'hConvoEdit' and store it in the char array 'dispname' which is from a class.

    Code:
    GetWindowText(hConvoEdit, options.dispname, 32);
    My program runs but nothing is being stored into 'dispname'. Could someone please explain why and what It is I have done wrong here.

    Thanks.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Have you stored the handle in hConvoEdit? (Are you _sure_?) Is dispname actually empty?

    From your example, I don't think the board can help you. Show us where you:
    1) Create the window hConvoEdit, and store the handle in that variable.
    2) Display the value in options.dispname
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    'hConvoEdit' is a global variable:
    Code:
    HWND hConvoEdit;
    This is where 'options.dispname' is created inside a class:
    Code:
        public:
            char dispname[32];
    And I am tryng to dispay the value of 'options.dispname' in a message box to test that my code is working (which at present it isn't). the message box is created within a dialog procedure in the event that a button is pressed.
    Code:
    case ID_OPTSOK:
    {
                        GetWindowText(hConvoEdit, options.dispname, 32);
                        MessageBox(hwnd, options.dispname, "test", MB_OK | MB_ICONEXCLAMATION);
                        EndDialog(hwnd, ID_OPTSOK);
    }break;
    Thanks for your time.

  4. #4
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    2/3, and I still see nothing really wrong. But:
    Quote Originally Posted by Cactus_Hugger
    Show us where you:
    1) Create the window hConvoEdit
    I'd still like to see that part. Make sure you're actually initializing your variable somewhere before you ask for the window's text. (You could also check GetWindowText()'s return value...)

    You're editing a public variable of a class... that may or may not be a good thing...
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  5. #5
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    Oh yeah sorry, forgot to post that bit.

    Here it is:
    Code:
    hConvoEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
                        WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 
                        0, 20, 524, 308, hwnd, (HMENU)ID_CONVOEDIT, GetModuleHandle(NULL), NULL);
    I checked the return value of GetWindowText() and it's returning 0.

    What do you mean by:
    You're editing a public variable of a class... that may or may not be a good thing...
    ?

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Try GetLastError().
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  7. #7
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    You're not assigning any text to the edit control.

    Code:
    hConvoEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "Text should go here", 
                        WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY, 
                        0, 20, 524, 308, hwnd, (HMENU)ID_CONVOEDIT, GetModuleHandle(NULL), NULL);
    Or are you setting the value somewhere else?

  8. #8
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    LOL. Sorry I've been trying to get text from the wrong edit control. Doh!

    Ive decided not to use a class now.

    now Ive a got a problem with this though (from my dialog procedure):

    Code:
    char buf[32];
    HWND hNameEdit = GetDlgItem( GetDlgItem(hwnd, ID_OPTSDIAG), ID_NAMEEDIT );
    int tmp = GetWindowText(hNameEdit, buf, 32);
    if(tmp==0){MessageBox(hwnd, "GetWindowText() returned 0!", "Error", MB_OK | MB_ICONEXCLAMATION);}
    I'm not getting anything stored in 'buf' and im getting 0 returned from GetWindowText(). is there a problem with this code?

    Or is there something wrong with the resource for the dialog and edit? Code for that:

    Code:
    // Options Dialog
    ID_OPTSDIAG DIALOG DISCARDABLE  80, 30, 175, 100
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Options"
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "OK", ID_OPTSOK, 25, 70, 50, 20
        PUSHBUTTON      "Cancel", ID_OPTSCNCL, 95, 70, 50, 20
        LTEXT           "Display name:", -1, 10, 15, 45, 10
        EDITTEXT        ID_NAMEEDIT, 60, 14, 90, 11
        LTEXT           "Text colour:", -1, 10, 40, 45, 10
        PUSHBUTTON      "Select Colour", ID_COLRBUTTON, 60, 38, 90, 12
    END

    This is where I create the dialog from the resource:

    Code:
    DialogBox(GetModuleHandle(NULL), 
                                MAKEINTRESOURCE(ID_OPTSDIAG), hwnd, OptsDiagProc);
    Last edited by switchcase; 05-29-2007 at 03:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetwindowText problem
    By spanker in forum Windows Programming
    Replies: 4
    Last Post: 03-27-2008, 11:25 AM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21