Change the caption of a Button
To Change the Button's Caption
First we must create a Member Variable for the Button. Follow these sets to create it.
- Go to View > Class Wizard (Or press Ctrl + W)
- Go to the Member Variables tab.
- There should be a list of your Control ID's. Select your Control and press the Ad Variable button on the right.
- Enter the name m_bButton. (make sure that the Catagory is Control and the Variable type is CButton). Click OK.
- Go back to your Dialog and double click the button. If it is your first time going into the code of the button, you should be prompted with a MessageBox. Just click ok and accept the default settings.
- Now you should be in the source window where you can see all of your code. Fill in the following code as follows
Code:
void CNotepadDlg::OnButton10()
{
// Declare a string named MyString and give it the value of "Hello"
CString MyString = "Hello";
// Change the Button's text to MyString
m_bButton.SetWindowText(MyString);
}