解決步驟
- 在對應的
dialog
cpp 文件里面的在OnInitDialog
函數里面,找到對應的位置,您需要結束窗體顯示的地方。(感覺這是廢話) - 經過驗證,使用
EndDialog(IDCANCEL);//這一句就起到了效果
代碼片段如下
BOOL CMy001_CloseDialogOnInitDialogDlg::OnInitDialog()
{
int nMERet = IDCANCEL;
CDialogEx::OnInitDialog();
// 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
/*
在這兒進行一些驗證性的工作,通過則顯示窗體,失敗則退出
*/
nMERet = MessageBox(_T("驗證窗體,點擊OK顯示窗體,點擊Cancel關閉窗體"),
_T("驗證窗體"),
MB_OKCANCEL);
if ( nMERet != IDOK )
{
EndDialog(IDCANCEL);//這一句就起到了效果
return FALSE;//同時,我喜歡加上這一句
}
return TRUE; // return TRUE unless you set the focus to a control
}
MFC題外話
其實不想記錄這個問題的,因為沒有什么實質性的價值。在網上找找就可以找到的。但不知為什么,這個問題確出現在了我的記錄里面,也許是因為現在已經知道了。我記得當初我是廢了一些時間的。無語,這么糾結。希望能幫助有用的人吧。不過MFC這東西,說真的,不太喜歡。就是不喜歡,沒有為什么,不喜歡,不喜歡,就是不喜歡。
參考文獻