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. How to create a text field within a dialog box

How to create a text field within a dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
6 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.
  • D Offline
    D Offline
    Deepak Samuel
    wrote on last edited by
    #1

    Hi, I need to create a text field within a dialog box, where i want some data to be printed out (i.e., to show) . How do I start ? Thanks, Deepak Samuel

    P 1 Reply Last reply
    0
    • D Deepak Samuel

      Hi, I need to create a text field within a dialog box, where i want some data to be printed out (i.e., to show) . How do I start ? Thanks, Deepak Samuel

      P Offline
      P Offline
      PremL
      wrote on last edited by
      #2

      I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation

      A M 2 Replies Last reply
      0
      • P PremL

        I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation

        A Offline
        A Offline
        armentage
        wrote on last edited by
        #3

        You might want to consider using an EDIT control instead of a STATIC, and then set the ReadOnly property on it. The advantage is that users will be able to copy & scroll the data in the control. If you don't plan on displaying all that much data, then maybe the STATIC is the right way to go.

        1 Reply Last reply
        0
        • P PremL

          I assume you already have a dialog working. Got to the resource editor and add a static text control. Its ID is going to be IDC_STATIC change that to your own ID. Like IDC_MYTEXT. What you put as the text of the static control is going to be the text that is initially displayed. Now, in one of your dialog message handler, wherever you want to change the text on the dialog, put the following: CStatic* pText = (CStatic*) GetDlgItem(IDC_MYTEXT); //get a pointer to the control pText->SetWindowText(“Hello World”); //set the text When the message handler is called the text is going to change to Hello World. This works with an edit box too. Make an Edit box on your resource template with ID IDC_MYEDIT. The following code will display the text. CEdit* pEdit = (CEdit*) this->GetDlgItem(IDC_MYEDIT); pEdit->SetWindowText("Hello World"); I hope this helps. Lorenz Prem Microsoft Corporation

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          Jeez, even the guys at MS don't know about SetDlgItemText. I don't know about you, but I find a one-liner much more readable: SetDlgItemText( IDC_MYEDIT, _T( "Hello World" ) ); Also, there's no need to cast to a CEdit or CStatic pointer if you're just going to be calling a method implemented on CWnd.

          P 1 Reply Last reply
          0
          • M Mike Dimmick

            Jeez, even the guys at MS don't know about SetDlgItemText. I don't know about you, but I find a one-liner much more readable: SetDlgItemText( IDC_MYEDIT, _T( "Hello World" ) ); Also, there's no need to cast to a CEdit or CStatic pointer if you're just going to be calling a method implemented on CWnd.

            P Offline
            P Offline
            PremL
            wrote on last edited by
            #5

            I agree that your solution is much more elegant and readable, but getting a pointer to the control is also a vital step in many other not so basic scenarios. I figure I better answer the question the way it is most useful, not necessarily in the shortest way. That includes the cast, which might be necessary for other things besides setting the text. Lorenz Prem Microsoft Corporation

            I 1 Reply Last reply
            0
            • P PremL

              I agree that your solution is much more elegant and readable, but getting a pointer to the control is also a vital step in many other not so basic scenarios. I figure I better answer the question the way it is most useful, not necessarily in the shortest way. That includes the cast, which might be necessary for other things besides setting the text. Lorenz Prem Microsoft Corporation

              I Offline
              I Offline
              igor1960
              wrote on last edited by
              #6

              Wow!!! Lorenz Prem Microsoft Corporation Does that mean that we are getting an official MSFTs responce now? "...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..." Me

              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