你可以按照如下方法使用: CAaDlg *dlg = new CAaDlg(); dlg->Create(IDD_AA_DIALOG); m_pMainWnd = dlg; dlg->ShowWindow(SW_HIDE); /* int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } */
我猜是模式的,如果是模式的,应该一开始没办法让它隐藏,试想一下,模式对话框一出现就隐藏了,而主窗口有没有焦点,那谁来响应你呢?呵呵
如果要实现隐藏,建议用非模式对话框,用ShowWindow(SW_HIDE);就可以了
CAaDlg *dlg = new CAaDlg();
dlg->Create(IDD_AA_DIALOG);
m_pMainWnd = dlg;
dlg->ShowWindow(SW_HIDE);
/* int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
*/
是在程序运行后,暂时不显示该窗体。ShowWindow(SW_HIDE); 可以隐藏窗体,但是要等到窗口出来后才行。
肯定能隐藏窗体
CTestHideDialogDlg *dlg = new CTestHideDialogDlg();
m_pMainWnd = dlg;
if (dlg!=NULL) {
BOOL ret = dlg->Create(IDD_TESTHIDEDIALOG_DIALOG);
if(!ret){
AfxMessageBox("Error creating Dialog");
return FALSE;
}
dlg->ShowWindow(SW_HIDE);
}
else
AfxMessageBox("Error Creating Dialog Object");注意的是需要在这段代码后面加上一个消息循环,否则程序会自动退出。
BOOL bRet;
MSG msg;while ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 )
{
if (bRet == -1 )
{
}
else if (msg.message == WM_COMMAND && msg.wParam == IDOK) {
break;
}
else if (!IsWindow(m_pMainWnd->m_hWnd) || !IsDialogMessage(m_pMainWnd->m_hWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
设置为按下对话框上的OK键时退出程序。