Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Text Boxes in C++

Text Boxes in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gktony
    wrote on last edited by
    #1

    Hi all, I am new to C++ and I want to get the value from a text box merge it with another string and then re-populate the text box. I am using the text box in a windows form. Here is the code I have tried but doesn't work string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1"; Thanks Ben

    _ O E G 4 Replies Last reply
    0
    • G Gktony

      Hi all, I am new to C++ and I want to get the value from a text box merge it with another string and then re-populate the text box. I am using the text box in a windows form. Here is the code I have tried but doesn't work string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1"; Thanks Ben

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      You would be having some control for the text box. If not go to class wizard and create it. Let us name it as tb.Now you can access the text box text by calling GetWindowText. Modify the string and use SetWindowText to set the text back to the text box Regards Anshuman

      1 Reply Last reply
      0
      • G Gktony

        Hi all, I am new to C++ and I want to get the value from a text box merge it with another string and then re-populate the text box. I am using the text box in a windows form. Here is the code I have tried but doesn't work string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1"; Thanks Ben

        O Offline
        O Offline
        Owner drawn
        wrote on last edited by
        #3

        For this you have to use SetWindowText() and GetWindowText().

        BOOL SetWindowText(
        HWND hWnd,
        LPCTSTR lpString
        );

        int GetWindowText(
        HWND hWnd,
        LPTSTR lpString,
        int nMaxCount
        );

        TCHAR lpString[100]; GetWindowText(hEdit, lpString, sizeof(lpstring)) _tcscat(lpString, " another string"); SetWindowText(hEdit, lpString) Now this will work.:)

        Jesus Loves:rose:

        --Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:

        T 1 Reply Last reply
        0
        • O Owner drawn

          For this you have to use SetWindowText() and GetWindowText().

          BOOL SetWindowText(
          HWND hWnd,
          LPCTSTR lpString
          );

          int GetWindowText(
          HWND hWnd,
          LPTSTR lpString,
          int nMaxCount
          );

          TCHAR lpString[100]; GetWindowText(hEdit, lpString, sizeof(lpstring)) _tcscat(lpString, " another string"); SetWindowText(hEdit, lpString) Now this will work.:)

          Jesus Loves:rose:

          --Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          prefer the GetWindowText() and SetWindowText() that handles CStrings :

          CString strMsg = " World";
          CString strEditContent; //let's say "Hello"

          //gets the edit handle
          CEdit* pEdit = (CEdit*)GetDlgItem(IDC_MY_EDIT);

          //gets the edit string
          pEdit->GetWindowText(strEditContent);

          //concatenate the strings
          strEditContent += strMsg;

          //sets the edit string
          pEdit->SetWindowText(strEditContent);


          TOXCCT >>> GEII power
          [toxcct][VisualCalc 2.20][VisualCalc 3.0] -- modified at 7:18 Monday 16th January, 2006

          O 1 Reply Last reply
          0
          • T toxcct

            prefer the GetWindowText() and SetWindowText() that handles CStrings :

            CString strMsg = " World";
            CString strEditContent; //let's say "Hello"

            //gets the edit handle
            CEdit* pEdit = (CEdit*)GetDlgItem(IDC_MY_EDIT);

            //gets the edit string
            pEdit->GetWindowText(strEditContent);

            //concatenate the strings
            strEditContent += strMsg;

            //sets the edit string
            pEdit->SetWindowText(strEditContent);


            TOXCCT >>> GEII power
            [toxcct][VisualCalc 2.20][VisualCalc 3.0] -- modified at 7:18 Monday 16th January, 2006

            O Offline
            O Offline
            Owner drawn
            wrote on last edited by
            #5

            Hmmm, you are right. But seeing his post I thought he must be using SDK.

            Jesus Loves:rose:

            --Owner Drawn:rose: --Nothing special --Defeat is temporary but surrender is permanent --Never say quits --Jesus is Lord:rose:

            1 Reply Last reply
            0
            • G Gktony

              Hi all, I am new to C++ and I want to get the value from a text box merge it with another string and then re-populate the text box. I am using the text box in a windows form. Here is the code I have tried but doesn't work string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1"; Thanks Ben

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #6

              Gktony wrote:

              string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1";

              this is certainly a VB++!! :)


              0x0400: "But your mind is very complex, very tricky. It makes simple things complicated. -- that's its work. And for centuries it has been trained for only one thing: to make things so complicated that your life becomes impossible."- Osho

              --[V]--

              1 Reply Last reply
              0
              • G Gktony

                Hi all, I am new to C++ and I want to get the value from a text box merge it with another string and then re-populate the text box. I am using the text box in a windows form. Here is the code I have tried but doesn't work string S1; S1 = this->textBox1->Text; textBox1->Text = S1 + "Test1"; Thanks Ben

                G Offline
                G Offline
                Gktony
                wrote on last edited by
                #7

                Thank you all for your replies. I see you are using SetWindowText() and GetWindowText(). In the meantime I have tried the following and it worked. String* S1 = textBox1->Text; textBox1->Text = String::Concat(S1, S"Test"); Am I not suppose to code like that in C++ as there are better way of doing it? Thanks Ben

                T 1 Reply Last reply
                0
                • G Gktony

                  Thank you all for your replies. I see you are using SetWindowText() and GetWindowText(). In the meantime I have tried the following and it worked. String* S1 = textBox1->Text; textBox1->Text = String::Concat(S1, S"Test"); Am I not suppose to code like that in C++ as there are better way of doing it? Thanks Ben

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  it seems that there had a misunderstood. you are coding for .NET framework (so your question should be asked in the C++/CLI forum). our answer were in fact for Win32 / MFC... so don't take them in account.


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc 2.20][VisualCalc 3.0]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups