API Text box prob

This is a discussion on API Text box prob within the C++ Programming forums, part of the General Programming Boards category; how do i use the function: Code: int GetDlgItemText( int nID, LPTSTR lpStr, int nMaxCount ) const; int GetDlgItemText( int ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    19

    API Text box prob

    how do i use the function:
    Code:
    int GetDlgItemText( int nID, LPTSTR lpStr, int nMaxCount ) const; 
    
    int GetDlgItemText( int nID, CString& rString ) const;
    I need it to read from a Text box and then change it to a variable so i can use it else where when i call it back. ( i play a game so when they enter the account name it takes it has a variable then i have it add the variable to the "Account Name" box on the game itself ) I use Borland's C++ Builder so...Any help is appreciated.

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Looks like you pass the controls ID as the first argument, and the destination variable in the second.

    The one that has 3 variables is overloaded so you can determine the number of characters to read.

    (Im just guessing here. Google it and it will probably bring up many links)

    To put it into a control use SetDlgItemText

    [EDIT]
    Just for future posts.
    There is a Windows programming forum on this board.
    Questions related to the WinAPI will have a much better chance of being answered there
    Last edited by Vicious; 09-12-2004 at 01:49 PM.
    What is C++?

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Here's an example (assuming you already created an edit control):

    Code:
    char* text;
    
    //get length of text in edit
    int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_MAIN_TEXT)); 
    text = new char[++len]; //allocate space for text
    //(length doesn't include space for null character)
    
    //store the text into the text variable
    GetDlgItemText(hwnd, IDC_MAIN_TEXT, text, len);
    
    //display it in a message box 
    MessageBox(hwnd, text, "The current text is:",MB_OK);
    "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

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    19
    Doesnt even work...Im using Borlands C++ and the controls name is Edit3

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    19
    [C++ Error] Unit1.cpp(22): E2451 Undefined symbol 'hwnd'
    [C++ Error] Unit1.cpp(22): E2451 Undefined symbol 'IDC_MAIN_TEXT'
    are the errors

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    How about posting your code? It would be easier to show you how to fit the code into your program
    "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
    Jul 2004
    Posts
    19
    Code:
    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    
    }
    //---------------------------------------------------------------------------
    I want it to check it once they click the Button (Button2) and check the Edit3 Box

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>Doesnt even work...Im using Borlands C++ and the controls name is Edit3
    xD Dude, it wasn't supposed to work. He didn't know anything about your program, what anything was called, what was declared and what wasn't... he gave you a template to follow, and you were supposed to fill in the placeholders with the actual names of things (for example IDC_MAIN_TEXT)!

    In fact, it doesn't look like the code will even work at all with the code you have... you're using some weird wrapper classes that Borland provides or something, which as far as I know is very different from 'pure' Windows API code.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    [C++ Error] Unit1.cpp(22): E2451 Undefined symbol 'hwnd'
    [C++ Error] Unit1.cpp(22): E2451 Undefined symbol 'IDC_MAIN_TEXT'
    are the errors
    hwnd is the handle to your dialog's window. IDC_MAIN_TEXT is the name of your Edit box (check your resource editor to see what its name is).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obtaining a value from a text box
    By thetinman in forum Windows Programming
    Replies: 1
    Last Post: 11-23-2006, 04:50 PM
  2. Win32 API - Group Box Control
    By Matt-Stevens in forum Windows Programming
    Replies: 2
    Last Post: 09-05-2006, 08:46 AM
  3. Automatically enter text in a dialog box
    By leojose in forum Windows Programming
    Replies: 6
    Last Post: 12-13-2005, 10:59 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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