單擊標(biāo)簽ClassView(這里顯示的是[Class…])就可以看到Eg02這個(gè)應(yīng)用程序的類.第一個(gè)CAboutDlg就是關(guān)于對話框的類.CEg02Dlg對應(yīng)IDD_EG02_DIALOG.中間的Ceg02App是應(yīng)用程序的基礎(chǔ)類.所以,如果要對關(guān)于對話框進(jìn)行操作,就要用到類CAboutDlg,因?yàn)榕c此有關(guān)的函數(shù)及變量都封裝在CAboutDlg中.看到這里大家可能又糊涂了,沒關(guān)系,在以后的教程中,通過一些練習(xí)大家就會(huì)慢慢領(lǐng)會(huì)到的.這里還是先為[關(guān)于]按鈕添加代碼.
void CEg02Dlg::OnBtnAboutme()
{
// TODO: Add your control notification handler code here
}
上面是VC為[關(guān)于]按鈕添加的響應(yīng)函數(shù).我們添加代碼成以下所示
void CEg02Dlg::OnBtnAboutme()
{
// TODO: Add your control notification handler code here
CAboutDlg ADlg;
ADlg.DoModal();
}
一共有兩句,第一句是CAboutDlg ADlg;作用是定義一個(gè)變量Adlg.第二句是ADlg.DoModal();功能是調(diào)用類CAboutDlg里的一個(gè)函數(shù)DoModal();這個(gè)函數(shù)在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.一般我們用于顯示一個(gè)對話框.其實(shí)大家看看CAboutDlg這個(gè)類下面,只有兩個(gè)函數(shù)
// 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); //這里是添加的,別的都是自動(dòng)生成的
return TRUE; // return TRUE unless you set the focus to a control
}
在這里我們只添加SetTimer(0,500,NULL);其中,參數(shù)0代表定時(shí)器的ID號為0,.第二個(gè)參數(shù)500是定時(shí)器的時(shí)間,單位為ms,后面的NULL是指不要回調(diào)函數(shù).
按F7編譯后運(yùn)行就可以看到運(yùn)行效果了.