-
March 22nd, 2007, 03:43 PM
#1
MFC static text control
I have a static text control in an mfc application. I want to add some text and such to it. Im new to mfc but I thought I add a control variable to change the caption property. When I right click the control and pick add variable I just get a blank menu with no datatypes for control variable of value or control type. I tried adding a CString and typing that into the dataype box but it didnt work. Am I doing anything stupid?
Last edited by abcdefgqwerty; March 22nd, 2007 at 03:48 PM.
-
March 22nd, 2007, 04:09 PM
#2
Re: MFC static text control
Add a member variable to the control of type CString.
if m_Edit is your member variable then,
Code:
UpdateData();
m_Edit = "My first Text";
UpdateData(FALSE);
Thats it.
Method 2:
Code:
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT);
pEdit->SetDlgItemText........
Happy Coding
"Dont Forget to rate if it helped"
-
March 22nd, 2007, 04:15 PM
#3
Re: MFC static text control
Can I cast CWnd * to a pointer of any control type? Ive seen a CWnd* being cast into a listcontrol * once.
-
March 22nd, 2007, 04:19 PM
#4
Re: MFC static text control
Dude,
OOps! my mistake, i thought of Edit control but you are asking for just static text.
Go to OnInitDialog() and just add this line
Code:
SetDlgItemText(IDC_STATIC,"My First Static Text");
"Dont Forget to rate if it helped"
-
March 22nd, 2007, 04:22 PM
#5
Re: MFC static text control
its ok thanks for the help. My problem was a bug in MFC where I guess the control didnt work right until I deleted it and put it back on the page. That or I did something stupid which is most likely I guess.
That worked on setting the text, mfc is pretty confusing at first. C# is a lot more elegant and has less bugs.
Last edited by abcdefgqwerty; March 22nd, 2007 at 04:39 PM.
-
March 22nd, 2007, 08:49 PM
#6
Re: MFC static text control
 Originally Posted by abcdefgqwerty
mfc is pretty confusing at first. C# is a lot more elegant and has less bugs.
Well, C# has the benefit of the long history of C++ behind it, and, of course, C++ was built on the experience of C.
Although I would also add that how confusing a language is to someone just learning it is often a combination of the learner's past experience and, more importantly, the teacher's effectiveness in teaching (or alternatively how well-written the book is that the learner is using). Unfortunately there are a lot of bad teachers and a lot of poorly written books out there.
-
April 24th, 2025, 07:17 AM
#7
Re: MFC static text control
 Originally Posted by VCVCVC
Dude,
OOps! my mistake, i thought of Edit control but you are asking for just static text.
Go to OnInitDialog() and just add this line
Code:
SetDlgItemText(IDC_STATIC,"My First Static Text");
Yeah well, this is wrong as well.
So go to your OnInitDialog() and in that, after all default initializations, give error due to My First Static Text. Also, its showing that IDC_STATIC is not declared.
-
April 24th, 2025, 09:21 AM
#8
Re: MFC static text control
 Originally Posted by GURUKARTHI K C
Yeah well, this is wrong as well.
So go to your OnInitDialog() and in that, after all default initializations, give error due to My First Static Text. Also, its showing that IDC_STATIC is not declared.
Well, after 18+ years (the age of the thread)... 
Are you sure someone who posted to this thread still attends (sometimes) the CG?
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|