Log in

View Full Version : Newbie: eVC++: Changing Static Text caption, how to?


PPCdev
02-08-2003, 02:18 AM
I know Im asking some pretty basic questions, and your patience is grand. The way I learn is to take itty bitty building blocks and build on top of them, so as I learn the baby steps I can progress more on my own and my questions eventually end up being more advanced in nature.

At any rate, I have an MFC eVC++ app that has a button on it... And, a static text with the caption set. I want to change the caption when the button is clicked, but I dont know how to do that.

In VB it would be something like:

lable1.caption = "This is the new text"

Please forgive me for I am a SuperNewbie, but be thankful I am joining the mature ranks of 'C' programmers! :-)

I am getting excelent advice from this forum, and if theres no objection I hope to post more Newbie questions as I progress in my learning. Ive subscibed to other forums just for developers, but questions sit idle there for days and days with no response. :-( This is the only forum Ive found that was active and members actually contribute. I hope to be able to help others as you all have helped me!


Andrew Daniel

mel
02-08-2003, 02:49 AM
Simple, just use the SetWindowText function.

If you have declared a variable for the static control, you can do this:

m_wndCtrlName.SetWindowText(_T("Hello"));

If you don't have a variable, just do this:

GetDlgItem(IDC_CONTROLID)->SetWindowText(_T("Hello"));

OR, even easier...

SetDlgItemText(IDC_CONTROLID, _T("Hello"));

In the above examples, IDC_CONTROLID is the id of the control on your dialog box. By default, eVC will call it IDC_STATIC. You need to change it yourself to something else...(e.g: IDC_LABEL1)

btw, don't be so apologetic about asking a simple question, we've all been there :)

PPCdev
02-08-2003, 03:29 AM
Worked like a champ Mel, thanks!

Is there any books for retards like me that detail this type of beginner code? I cant find one... and Ive looked, and looked and .........

mel
02-08-2003, 03:53 AM
Sam's "Teach Yourself Visual C++ in 21 days" is a good one for a beginner.

You don't need to get a book on embedded Visual C++. Any good Visual C++ 6.0 book will do. All the VC++ code, the IDE user interface and almost everything is identical to eVC++.

Kati Compton
02-08-2003, 03:57 AM
Sam's "Teach Yourself Visual C++ in 21 days" is a good one for a beginner.

You don't need to get a book on embedded Visual C++. Any good Visual C++ 6.0 book will do. All the VC++ code, the IDE user interface and almost everything is identical to eVC++.

That's not QUITE true, as eVC is really a subset of VC++. But I do endorse getting a VC++ book, as it will be right most of the time, and will at least give you an idea of what you need for the times it's not right. If something doesn't work like expected from the book, the eVC help files should clarify.