Click to See Complete Forum and Search --> : Setting Control Properties


Hexie
April 21st, 1999, 10:18 PM
Hi, I am a VB programmer learning MFC.
I have a label on a dialog I have a button on a dialog. When I click the button I want to change the caption of the label. What is the syntax?
I have tried the following.
CString temp = "New Caption.";
label1.Caption = temp;

The line "label1.Caption = temp;" causes a compile error because I do not have a class name in front of it. My dialog is named form1. I have tried:
Form1::label1.caption = temp;
This produces even more compiler errors.
Can any of you Gurus convert this simple VB statement to MFC?

Form1.Label1.Caption = temp

Thank You
Hexie

Lynx
April 21st, 1999, 10:30 PM
Use SetWindowText() to change the dialog's title, editbox's text, or a static text. For example,

// the label you create is a StaticText with resource ID (IDC_STATIC1)
CStatic *pLabel = (CStatic*)GetDlgItem(IDC_STATIC1);
ASSERT(pLabel != NULL);

pLabel->SetWindowText("New Caption");
// done


If you want to change dialog's title, simply call the same function:
SetWindowText("New Title"); // must be called within the dialog class

Hope this will help. Good luck.

Lynx

Hexie
April 22nd, 1999, 07:37 AM
Hi Lynx,
Thanks for responding to my post on setting properties.
My post was a generalized case however, I need to know how to set any property. Setting the caption of a label was not my goal. Mostly I need to know how to access any property of a custom control.
I have a custom image box OCX made by ImageFX. It has a property call "FileName".I need to assign a string to this property to activate its internal method of loading a picture. In VB the code would look lie this:

Form1.imgFX.FileName = "C:\myfile.bmp"

So I need to assign a string to a property. Mainly I need to know what the syntax is for accessing Form1.
Form1::imgFX.FileName = CString ("C:\myfile.bmp");
Does not work. Any ideas?
Hexie