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