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. Writing Variables in CDialog with MFC

Writing Variables in CDialog with MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
15 Posts 4 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.
  • N Offline
    N Offline
    NewbieStats
    wrote on last edited by
    #1

    Thanks to "toxcct" and "cedric moonen" Ive learned how to Link my CDialog's together, Thank you both! #include Button01Dlg.h void CClientDlg::OnButton01() { CButton01Dlg dlg; dlg.DoModal(); } But Ive come to Notice that only Text can be added to the CButton01Dlg on interface... I was wondering if there was a way to somehow get printf or cout working in Button01Dlg.cpp in order to apply variables?... Thanks for any Help you guys seem to be the best forum ive found yet! Just a Human Trying to Live in a Computers World.

    R D 2 Replies Last reply
    0
    • N NewbieStats

      Thanks to "toxcct" and "cedric moonen" Ive learned how to Link my CDialog's together, Thank you both! #include Button01Dlg.h void CClientDlg::OnButton01() { CButton01Dlg dlg; dlg.DoModal(); } But Ive come to Notice that only Text can be added to the CButton01Dlg on interface... I was wondering if there was a way to somehow get printf or cout working in Button01Dlg.cpp in order to apply variables?... Thanks for any Help you guys seem to be the best forum ive found yet! Just a Human Trying to Live in a Computers World.

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      NewbieStats wrote: to somehow get printf or cout working You could use sprintf() to write to a character string which could be displayed in a CStatic or CEdit control. NewbieStats wrote: Help you guys seem to be the best forum ive found yet! That's because we are the best programming forum on this planet. (Just my objective humble opinion). :) /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

      N C 2 Replies Last reply
      0
      • R Ravi Bhavnani

        NewbieStats wrote: to somehow get printf or cout working You could use sprintf() to write to a character string which could be displayed in a CStatic or CEdit control. NewbieStats wrote: Help you guys seem to be the best forum ive found yet! That's because we are the best programming forum on this planet. (Just my objective humble opinion). :) /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

        N Offline
        N Offline
        NewbieStats
        wrote on last edited by
        #3

        Would it Go under; CButton01Dlg::CButton01Dlg(CWnd* pParent /*=NULL*/) : CDialog(CButton01Dlg::IDD, pParent) { /* NULL */ } or void CButton01Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } or BEGIN_MESSAGE_MAP(CButton01Dlg, CDialog) END_MESSAGE_MAP() Sorry im kinda new at Interface programs... ive only made databases and so forth jus dos based... But those are the only 3 sections under Button01Dlg.cpp where would i enter it and would it look like; sprintf("%s %s you are %s years of age\n", First, Lastname, Age) /* Similar to regular printf? */ Just a Human Trying to Live in a Computers World.

        R 1 Reply Last reply
        0
        • N NewbieStats

          Would it Go under; CButton01Dlg::CButton01Dlg(CWnd* pParent /*=NULL*/) : CDialog(CButton01Dlg::IDD, pParent) { /* NULL */ } or void CButton01Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } or BEGIN_MESSAGE_MAP(CButton01Dlg, CDialog) END_MESSAGE_MAP() Sorry im kinda new at Interface programs... ive only made databases and so forth jus dos based... But those are the only 3 sections under Button01Dlg.cpp where would i enter it and would it look like; sprintf("%s %s you are %s years of age\n", First, Lastname, Age) /* Similar to regular printf? */ Just a Human Trying to Live in a Computers World.

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          What I meant was, you could use sprintf() (which works exactly like printf() but writes to a string vs. standard output) to display values of variables which could be shown by a static text control (i.e. CStatic) or an edit control (CEdit). The latter is preferred, since it supports scrolling, which can come in handy when displaying large amounts of text. The actual display would typically occur within a button handler. For example:

          CMyDialog::OnBtnFooClicked()
          {
          // Better to use a symbolic const instead of "256"
          char szResult [256];

          // Compute and display nFoo
          int nFoo = someFunction(...);
          sprintf (szResult, "nFoo = %d", nFoo);
          m\_myEditCtrl.SetWindowText (szResult);
          
          // Even better to use CString and Format()
          CString strResult;
          strResult.Format ("nFoo = %d", nFoo);
          m\_myEditCtrl.SetWindowText (strResult);
          

          Hope this helps. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          N 1 Reply Last reply
          0
          • R Ravi Bhavnani

            What I meant was, you could use sprintf() (which works exactly like printf() but writes to a string vs. standard output) to display values of variables which could be shown by a static text control (i.e. CStatic) or an edit control (CEdit). The latter is preferred, since it supports scrolling, which can come in handy when displaying large amounts of text. The actual display would typically occur within a button handler. For example:

            CMyDialog::OnBtnFooClicked()
            {
            // Better to use a symbolic const instead of "256"
            char szResult [256];

            // Compute and display nFoo
            int nFoo = someFunction(...);
            sprintf (szResult, "nFoo = %d", nFoo);
            m\_myEditCtrl.SetWindowText (szResult);
            
            // Even better to use CString and Format()
            CString strResult;
            strResult.Format ("nFoo = %d", nFoo);
            m\_myEditCtrl.SetWindowText (strResult);
            

            Hope this helps. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

            N Offline
            N Offline
            NewbieStats
            wrote on last edited by
            #5

            I understand now... Everything works out perfect besides for: "m_myEditCtrl" I appoligize for my illiterate-ness in MFC... C:\*\ClientDlg.cpp(190) : error C2065: 'm_myEditCtrl' : undeclared identifier C:\*\ClientDlg.cpp(190) : error C2228: left of '.SetWindowTextA' must have class/struct/union type Other then that i understand what you mean and how it will work, but what am i doing wrong when it comes to "m_myEditCtrl"? What do i replace it with? Just a Human Trying to Live in a Computers World.

            D R 2 Replies Last reply
            0
            • N NewbieStats

              Thanks to "toxcct" and "cedric moonen" Ive learned how to Link my CDialog's together, Thank you both! #include Button01Dlg.h void CClientDlg::OnButton01() { CButton01Dlg dlg; dlg.DoModal(); } But Ive come to Notice that only Text can be added to the CButton01Dlg on interface... I was wondering if there was a way to somehow get printf or cout working in Button01Dlg.cpp in order to apply variables?... Thanks for any Help you guys seem to be the best forum ive found yet! Just a Human Trying to Live in a Computers World.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              NewbieStats wrote: I was wondering if there was a way to somehow get printf or cout working in Button01Dlg.cpp in order to apply variables? No, those are for console-based applications.


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              1 Reply Last reply
              0
              • N NewbieStats

                I understand now... Everything works out perfect besides for: "m_myEditCtrl" I appoligize for my illiterate-ness in MFC... C:\*\ClientDlg.cpp(190) : error C2065: 'm_myEditCtrl' : undeclared identifier C:\*\ClientDlg.cpp(190) : error C2228: left of '.SetWindowTextA' must have class/struct/union type Other then that i understand what you mean and how it will work, but what am i doing wrong when it comes to "m_myEditCtrl"? What do i replace it with? Just a Human Trying to Live in a Computers World.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                NewbieStats wrote: C:\*\ClientDlg.cpp(190) : error C2065: 'm_myEditCtrl' : undeclared identifier The m_ implies that it is a (CEdit) member variable of the CClientDlg class.


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                1 Reply Last reply
                0
                • N NewbieStats

                  I understand now... Everything works out perfect besides for: "m_myEditCtrl" I appoligize for my illiterate-ness in MFC... C:\*\ClientDlg.cpp(190) : error C2065: 'm_myEditCtrl' : undeclared identifier C:\*\ClientDlg.cpp(190) : error C2228: left of '.SetWindowTextA' must have class/struct/union type Other then that i understand what you mean and how it will work, but what am i doing wrong when it comes to "m_myEditCtrl"? What do i replace it with? Just a Human Trying to Live in a Computers World.

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #8

                  m_myEditCtrl is a CEdit member of your dialog class, declared in the dialog's .h file. You will also need to associate the member with an edit control in your dialog template. You can do this dragging an edit control into your dialog template (using the resource editor) and using the ClassWizard to associate the CEdit member variable with the control. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                  N 1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    m_myEditCtrl is a CEdit member of your dialog class, declared in the dialog's .h file. You will also need to associate the member with an edit control in your dialog template. You can do this dragging an edit control into your dialog template (using the resource editor) and using the ClassWizard to associate the CEdit member variable with the control. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                    N Offline
                    N Offline
                    NewbieStats
                    wrote on last edited by
                    #9

                    Im still alittle Queued... In class wizard when i go to Member Variables the only Class ID's listed are "IDCANCEL" and "IDOK" the only choices i have are "Add Class" and "Add Variable" When i click on Add Variable it says "Member Variable Name: m_" where im guessing i put m_myEditCtrl... the only Catagory is "Control" and the only variable type is "CButton" but i dont want it to be a button? "m_myEditCtrl is a CEdit member of your dialog class, declared in the dialog's .h file." Where and what would i put in CButton01Dlg.h? (would this change my Class ID list to allow me to add it? "You can do this dragging an edit control into your dialog template (using the resource editor)" Resource Editor?... Dragging an edit control into your dialog template?... Im so Lost =/ Sorry again... Just a Human Trying to Live in a Computers World.

                    R 2 Replies Last reply
                    0
                    • N NewbieStats

                      Im still alittle Queued... In class wizard when i go to Member Variables the only Class ID's listed are "IDCANCEL" and "IDOK" the only choices i have are "Add Class" and "Add Variable" When i click on Add Variable it says "Member Variable Name: m_" where im guessing i put m_myEditCtrl... the only Catagory is "Control" and the only variable type is "CButton" but i dont want it to be a button? "m_myEditCtrl is a CEdit member of your dialog class, declared in the dialog's .h file." Where and what would i put in CButton01Dlg.h? (would this change my Class ID list to allow me to add it? "You can do this dragging an edit control into your dialog template (using the resource editor)" Resource Editor?... Dragging an edit control into your dialog template?... Im so Lost =/ Sorry again... Just a Human Trying to Live in a Computers World.

                      R Offline
                      R Offline
                      Ravi Bhavnani
                      wrote on last edited by
                      #10

                      NewbieStats wrote: Im still alittle Queued... You need to first add an edit control (eg: IDC_MY_EDIT) to your dialog template using the resource editor. Next, use the ClassWizard to add the m_myEditCtrl variable (category = Control). Since you're new to VC++, you may want to refer to an introductory text to help you get going. Meanwhile, see this[^] link to see how to add controls to a dialog template. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                      1 Reply Last reply
                      0
                      • N NewbieStats

                        Im still alittle Queued... In class wizard when i go to Member Variables the only Class ID's listed are "IDCANCEL" and "IDOK" the only choices i have are "Add Class" and "Add Variable" When i click on Add Variable it says "Member Variable Name: m_" where im guessing i put m_myEditCtrl... the only Catagory is "Control" and the only variable type is "CButton" but i dont want it to be a button? "m_myEditCtrl is a CEdit member of your dialog class, declared in the dialog's .h file." Where and what would i put in CButton01Dlg.h? (would this change my Class ID list to allow me to add it? "You can do this dragging an edit control into your dialog template (using the resource editor)" Resource Editor?... Dragging an edit control into your dialog template?... Im so Lost =/ Sorry again... Just a Human Trying to Live in a Computers World.

                        R Offline
                        R Offline
                        Ravi Bhavnani
                        wrote on last edited by
                        #11

                        It looks like the forum ate one of my replies. In answer to your question about the Control toolbar, here's how to display it: In VS2003, do View|Toolbox. In VC6, double-click the dialog in Resources tab, then right-click the workspace and select "Controls" from the popup menu. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                        N 1 Reply Last reply
                        0
                        • R Ravi Bhavnani

                          It looks like the forum ate one of my replies. In answer to your question about the Control toolbar, here's how to display it: In VS2003, do View|Toolbox. In VC6, double-click the dialog in Resources tab, then right-click the workspace and select "Controls" from the popup menu. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                          N Offline
                          N Offline
                          NewbieStats
                          wrote on last edited by
                          #12

                          Thanks! I still say this is the best forum ive seen =) Im going to try and work with ur tutorials your site provides so i can minimize on these post on the forum for newbie questions hehe... Thanks for puttin up wit my illiterate beginnings of MFC... Ill come back here if any questions or if i finish what im working on for feedback! thanks! Just a Human Trying to Live in a Computers World.

                          R 1 Reply Last reply
                          0
                          • N NewbieStats

                            Thanks! I still say this is the best forum ive seen =) Im going to try and work with ur tutorials your site provides so i can minimize on these post on the forum for newbie questions hehe... Thanks for puttin up wit my illiterate beginnings of MFC... Ill come back here if any questions or if i finish what im working on for feedback! thanks! Just a Human Trying to Live in a Computers World.

                            R Offline
                            R Offline
                            Ravi Bhavnani
                            wrote on last edited by
                            #13

                            NewbieStats wrote: Thanks for puttin up wit my illiterate beginnings of MFC... No thanks needed. We're here to help. Good luck! /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                            1 Reply Last reply
                            0
                            • R Ravi Bhavnani

                              NewbieStats wrote: to somehow get printf or cout working You could use sprintf() to write to a character string which could be displayed in a CStatic or CEdit control. NewbieStats wrote: Help you guys seem to be the best forum ive found yet! That's because we are the best programming forum on this planet. (Just my objective humble opinion). :) /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #14

                              Why recommend sprintf ? What's wrong with stringstream or even CString.Format ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                              R 1 Reply Last reply
                              0
                              • C Christian Graus

                                Why recommend sprintf ? What's wrong with stringstream or even CString.Format ? Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer

                                R Offline
                                R Offline
                                Ravi Bhavnani
                                wrote on last edited by
                                #15

                                It was the closest thing to printf() which he's familiar with. In my later post I recommended that he use CString::Format(). /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

                                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