Resize event example for C++ 5.0 and later
1. |
Add a Static Text control as follows: | |
|
a. |
In the Project Workspace, click the ResourceView tab. |
|
b. |
Double-click the tutor resources folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
d. |
Double-click IDD_TUTOR_DIALOG to design the dialog box. |
|
e. |
Click the Static Text control; then click and drag its shape in the dialog box. |
|
f. |
Double-click the new control to edit its properties. |
|
g. |
Change the ID to IDC_TEXT1. |
|
h. |
Press Ctrl-F4 to close all windows back to the Project Workspace. |
2. |
Do the following to add m_Text1 to the CTutorDlg class and link the variable to the Static Text control using dynamic data exchange: | |
|
a. |
Press Ctrl-W to go to the MFC ClassWizard. |
|
b. |
Click the Member Variables tab. |
|
c. |
In the Class Name box, select CTutorDlg. |
|
d. |
In the Control IDs list, select IDC_TEXT1. |
|
e. |
Click the Add Variable... button. |
|
f. |
Specify m_Text1 as the variable name, Control as the category, and Cstatic as the variable type. |
|
g. |
Click OK to close the dialog box, and click OK to close the MFC ClassWizard. |
3. |
Add a Command button to your project, and code its click procedure to resize the control using the MoveWindow function: |
m_LEADRasterView1.MoveWindow(0,0,100,100,TRUE);
4. |
Edit the OnResizeLead1 procedure as follows: |
void CTutorDlg::OnResizeLeadrasterview1()
{
TCHAR szText[128];
CRect rcWindow;
if (m_LEADRasterView1.m_hWnd)
{
m_LEADRasterView1.GetWindowRect(rcWindow);
wsprintf(szText, TEXT("Control size: %u, %u"), rcWindow.Width(), rcWindow.Height());
m_Text1.SetWindowText(szText);
m_Text1.UpdateWindow();
}
}