单击标签ClassView(这里显示的是[Class…])就可以看到Eg02这个应用程序的类.第一个CAboutDlg就是关于对话框的类.CEg02Dlg对应IDD_EG02_DIALOG.中间的Ceg02App是应用程序的基础类.所以,如果要对关于对话框进行操作,就要用到类CAboutDlg,因为与此有关的函数及变量都封装在CAboutDlg中.看到这里大家可能又糊涂了,没关系,在以后的教程中,通过一些练习大家就会慢慢领会到的.这里还是先为[关于]按钮添加代码.
void CEg02Dlg::OnBtnAboutme()
{
// TODO: Add your control notification handler code here
}
上面是VC为[关于]按钮添加的响应函数.我们添加代码成以下所示
void CEg02Dlg::OnBtnAboutme()
{
// TODO: Add your control notification handler code here
CAboutDlg ADlg;
ADlg.DoModal();
}
一共有两句,第一句是CAboutDlg ADlg;作用是定义一个变量Adlg.第二句是ADlg.DoModal();功能是调用类CAboutDlg里的一个函数DoModal();这个函数在MSDN里的解释是Call this member function to invoke the modal dialog box and return the dialog-box result when done. This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.一般我们用于显示一个对话框.其实大家看看CAboutDlg这个类下面,只有两个函数
// Set the icon for this dialog. The framework does this automatically
// when the application’s main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetTimer(0,500,NULL); //这里是添加的,别的都是自动生成的
return TRUE; // return TRUE unless you set the focus to a control
}
在这里我们只添加SetTimer(0,500,NULL);其中,参数0代表定时器的ID号为0,.第二个参数500是定时器的时间,单位为ms,后面的NULL是指不要回调函数.
按F7编译后运行就可以看到运行效果了.