Transferring a value to or from an MFC static text at runtime

Posted by Rey Dacoco in

By default, you cannot pass on a value to or from an MFC static text at runtime for the reason that it’s control ID doesn’t appear in the member variable’s tab when you activate the ClassWizard which precludes you to allocate a member variable to it. As you may know, the only way to pass a value to a control at runtime in MSVC++ is to map an instance variable to it. The following steps demonstrate how to make your static text control ID be made available in the ClassWizard ID list:


1. Add a static text control to your dialog-box by clicking on the Static text (Aa icon) and dragging it onto your dialog-box;


2. Your static text should now appear on your dialog with a default caption “Static”.



3. Right-click your static text>properties.


4.In the general tab, you will see the default ID of your Static text as IDC_STATIC.

STATIC in laypersons term means “unchanging” or “fixed” that’s why you cannot change its value at runtime. To be able to change its value, you’ll need to rename its ID from IDC_STATIC to IDC_WHATEVERDESCRIPTIVENAME, for instance IDC_NameLabel.


After changing its value from IDC_STATIC to IDC_WHATEVERDESCRIPTIVENAME, your Static text control should now appear in the ClassWizard ID lists, all you need to do is allocate a member variable to it so that you will be able to transfer a value to or from it at runtime. Same principle applies to Picturebox control.

0 comments

Post a Comment

Contributor

My photo
I am just a simple man with a simple mind. And this is my simple blog. New Posts will be available soon. Enjoy reading and never stop learning:)

Total Pageviews

Link List

Archives

Got questions? You can reach me here: