现在我有一个基于对话框的mfc的工程,现在由于界面需要变化,需要把另外一个新建的对话框作为主对话框(就是取代原来的),应该怎么弄?大家帮帮忙。

解决方案 »

  1.   

    在你的对话框程序的CXXAPP类的BOOL CXXXApp::InitInstance()函数里面,把下面的CXXXDlg换成你自己的对话框
    CXXXDlg dlg;
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();
    if (nResponse == IDOK)
    {
    // TODO: 在此放置处理何时用
    //  “确定”来关闭对话框的代码
    }
    else if (nResponse == IDCANCEL)
    {
    // TODO: 在此放置处理何时用
    //  “取消”来关闭对话框的代码
    }
      

  2.   

    在 CXXApp的InitInstance里面把
    CXXDlg dlg; //把这里改成新建对话框的类
    m_pMainWnd = &dlg;
    INT_PTR nResponse = dlg.DoModal();或者启动原窗口是隐藏,显示新建的窗口
      

  3.   

    可是我的InitInstance()里没有上面说的呀BOOL CRobot_00App::InitInstance()
    {
    AfxEnableControlContainer(); // 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 // Change the registry key under which our settings are stored.
    // TODO: You should modify this string to be something appropriate
    // such as the name of your company or organization.
    SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings();  // Load standard INI file options (including MRU) // Register the application's document templates.  Document templates
    //  serve as the connection between documents, frame windows and views. CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CRobot_00Doc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CRobot_00View));
    AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
    return FALSE; // The one and only window has been initialized, so show and update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow(); return TRUE;
    }
      

  4.   

    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CRobot_00Doc),
    RUNTIME_CLASS(CMainFrame), // main SDI frame window
    RUNTIME_CLASS(CRobot_00View));
    AddDocTemplate(pDocTemplate);// Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);// Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
    return FALSE;// The one and only window has been initialized, so show and update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    -------------------------------
    这些都去掉,然后用1#的代码
      

  5.   

    多谢各位的回答,csdn牛人真多。
      

  6.   

    现在我有一个CFormView的对话框窗口,如何把它加入到一个tabctrl中呢?很愁啊。
      

  7.   

    今天别人给我一个mfc工程,我看里面的资源里有一个对话框,双击一看不是CDialog类型的,而是CFormView的,不知道它们有什么区别,我想把它加到一个tabctrl中,应该怎么做?
      

  8.   

    楼主,你的问题解决了吗?我遇到一个类似问题
    我是之前做好了一个窗口工程,现在要在出现主窗口之前先弹出一个新建的窗口,也就是要把新建窗口设置为主窗口,请问该怎么改变代码呀? 
    我尝试在C***App::InitInstance()函数里做了如下修改: 
              //CSteelDlg dlg;//CSteelDlg是之前的主窗口类 
         Cwelcome dlg; //Cwelcome是想要设置的新主窗口类 
         m_pMainWnd = &dlg; 
         int nResponse = dlg.DoModal(); 
    这样修改的结果是,程序出现异常。什么窗口都弹不出来了。 
    请问这是什么原因?应该如何修改?