我在 OnCreate 函数和 OnInitDialog() 中都放置了 ShowWindow(SW_HIDE);
并且把对话框属性窗口中的 Visible 设置为 False 运行程序时,对话框还是显示。
真是没办法了 :(我用的是(VC7)

解决方案 »

  1.   

    楼主生成的是模式对话框还是非模式对话框啊?
    我猜是模式的,如果是模式的,应该一开始没办法让它隐藏,试想一下,模式对话框一出现就隐藏了,而主窗口有没有焦点,那谁来响应你呢?呵呵
    如果要实现隐藏,建议用非模式对话框,用ShowWindow(SW_HIDE);就可以了
      

  2.   

    你可以按照如下方法使用:
    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
    }
    */
      

  3.   

    新建一个 MFC 应用程序, 基于对话框, 是要把这个对话给隐藏。
    是在程序运行后,暂时不显示该窗体。ShowWindow(SW_HIDE); 可以隐藏窗体,但是要等到窗口出来后才行。
      

  4.   

    AfxGetApp->m_pMainWnd ->ShowWindow(SW_HIDE); 
    肯定能隐藏窗体
      

  5.   

    修改了linxy2002(阿郎----酷爱编程) 的做法,在VC7.0下试验
    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键时退出程序。