我利用MFC Wizard 建立一个基于对话框的工程,建立之后去掉对话框类,然后建立一个自己的窗口类,
在我建立好之后,编译、连接之后,在运行时,窗口一闪而过,这是为什么?
请大师指点!!!该如何显示它?

解决方案 »

  1.   

    这是因为你没有阻塞主线程,所以程序一下就结束了。
    基于对话框的工程,主窗口就是对话框,缺省是用DoModal调用对话框。DoModal会等到对话框退出后才继续向下执行。而你自己建立一个窗口,就相当于一个非模式对话框,当ShowWindow窗口后,程序是继续向下执行的,所以程序马上就结束了。
    可以考虑作个循环,判断窗口中的某个变量为true才结束循环。而窗口类的这个变量只有当窗口关闭时才设置为true>
      

  2.   

    BOOL CTest6App::InitInstance()
    {
    AfxEnableControlContainer();
    AfxInitRichEdit();
    // Standard initialization
    // If you are not using these features and wish to reduce the size
    //  of your final executable, you should remove from the following
    //  the specific initialization routines you do not need.#ifdef _AFXDLL
    Enable3dControls(); // Call this when using MFC in a shared DLL
    #else
    Enable3dControlsStatic(); // Call this when linking to MFC statically
    #endif
    //屏蔽原来的对话框
    // CTest6Dlg dlg;
    // m_pMainWnd = &dlg;
    // int nResponse = dlg.DoModal();         CMyDlg dlg;
             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
    }

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
    }
      

  3.   

    调用domodel()显示对话框
    C**Dlg dlg;
    dlg.domodel();