Writing Variables in CDialog with MFC
-
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. -
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.NewbieStats wrote: to somehow get printf or cout working You could use
sprintf()
to write to a character string which could be displayed in aCStatic
orCEdit
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 -
NewbieStats wrote: to somehow get printf or cout working You could use
sprintf()
to write to a character string which could be displayed in aCStatic
orCEdit
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.comWould it Go under;
CButton01Dlg::CButton01Dlg(CWnd* pParent /*=NULL*/) : CDialog(CButton01Dlg::IDD, pParent) { /* NULL */ }
orvoid CButton01Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); }
orBEGIN_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. -
Would it Go under;
CButton01Dlg::CButton01Dlg(CWnd* pParent /*=NULL*/) : CDialog(CButton01Dlg::IDD, pParent) { /* NULL */ }
orvoid CButton01Dlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); }
orBEGIN_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.What I meant was, you could use
sprintf()
(which works exactly likeprintf()
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
-
What I meant was, you could use
sprintf()
(which works exactly likeprintf()
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
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.
-
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.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
-
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.
NewbieStats wrote: C:\*\ClientDlg.cpp(190) : error C2065: 'm_myEditCtrl' : undeclared identifier The
m_
implies that it is a (CEdit
) member variable of theCClientDlg
class.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
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.
m_myEditCtrl
is aCEdit
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 theCEdit
member variable with the control. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com -
m_myEditCtrl
is aCEdit
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 theCEdit
member variable with the control. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.comIm 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.
-
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.
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 them_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 -
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.
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
-
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
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.
-
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.
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
-
NewbieStats wrote: to somehow get printf or cout working You could use
sprintf()
to write to a character string which could be displayed in aCStatic
orCEdit
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.comWhy 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
-
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
It was the closest thing to
printf()
which he's familiar with. In my later post I recommended that he useCString::Format()
. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com