Results 1 to 8 of 8

Thread: Reading from and write to a text box

  1. #1

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40

    Question Reading from and write to a text box

    O.S: Win98
    Compiler: Dev-C++ version 4
    Level: keen newbie

    Hello,

    I've created a text box (thanks to Vlatko and Steve) using CreateWindowEx function. I now need to know how you read from and write to the control.

    Thanks


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    SetWindowText(hEditCtl, "Text here!");
    Code:
    char *pcBuf;
    int iLen = GetWindowTextLength(hEditCtl);
    pcBuf = new char[iLen + 2];
    GetWindowText(hEditCtl, pcBuf, iLen + 1);
    // use pcBuf, then delete it
    delete[] pcBuf;
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    You can also send the WM_SETTEXT message. First get the textlength by sending the WM_GETTEXTLENGTH message:
    WM_SETTEXT
    An application sends a WM_SETTEXT message to set the text of a window.

    WM_SETTEXT
    wParam = 0; // not used; must be zero
    lParam = (LPARAM)(LPCTSTR)lpsz; // address of window-text string

    Parameters
    lpsz
    Value of lParam. Pointer to a null-terminated string that is the window text.
    Return Values
    The return value is TRUE if the text is set. It is FALSE (for an edit control), LB_ERRSPACE (for a list box), or CB_ERRSPACE (for a combo box) if insufficient space is available to set the text in the edit control. It is CB_ERR if this message is sent to a combo box without an edit control.
    But the result is the same.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40

    Thumbs up One step closer..

    Thanks parksie and Vlatko


  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    If you're dealling with Dialog, you can use the SendDlgItemMessage or SetDlgItemText Api function call, so, all you need to know is the control ID and not the handle (HWND)


    PHP Code:
    // Read the string from IDC_EDIT control
    int    sz=0;
    char    *str;

    sz SendDlgItemMessage(hDlgIDC_EDIT1WM_GETTEXTLENGTH00);
    sz sz+1;
    str = new char[sz];
    memset(str0sz);
    SendDlgItemMessage(hDlgIDC_EDIT1WM_GETTEXTsz, (LPARAM)str);
    MessageBox(hDlgstrNULL,  MB_OK);
    delete [] str;


    // Write a new string into IDC_EDIT control
    SetDlgItemText(hDlgIDC_EDIT1"TESTING"); 
    regards,

  6. #6

    Thread Starter
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40
    Thanks Chris


  7. #7
    Junior Member
    Join Date
    Apr 2001
    Posts
    22
    Chris,

    How would one adapt this for use in VB ?

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    VB Code:
    1. txtMyTextBox.Text = "whatever"
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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