工控编程吧

标题: 上位机MFC多文档程序打开时如何不创建子框架 [打印本页]

作者: qq263946146    时间: 2019-7-24 12:30
标题: 上位机MFC多文档程序打开时如何不创建子框架
在我们使用多文档程序框架时,程序打开会默认打开一个子框架窗口。
我们也可通过代码取消这个默认动作。
即主框架不打开任何子框架窗口。
我们知道在app类的函数InitInstance()内有一段代码
        CCommandLineInfo cmdInfo;
        ParseCommandLine(cmdInfo);


下面还有一段解析指令的代码
        if (!ProcessShellCommand(cmdInfo))
        {
                return FALSE;
        }

我们只要在两段代码间修改下cmdInfo的成员变量就好
        cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
最终代码段为:
  1. BOOL CDemoApp::InitInstance()
  2. {
  3.         AfxEnableControlContainer();

  4.         // Standard initialization
  5.         // If you are not using these features and wish to reduce the size
  6.         //  of your final executable, you should remove from the following
  7.         //  the specific initialization routines you do not need.

  8. #ifdef _AFXDLL
  9.         Enable3dControls();                        // Call this when using MFC in a shared DLL
  10. #else
  11.         Enable3dControlsStatic();        // Call this when linking to MFC statically
  12. #endif

  13.         // Change the registry key under which our settings are stored.
  14.         // TODO: You should modify this string to be something appropriate
  15.         // such as the name of your company or organization.
  16.         SetRegistryKey(_T("Local AppWizard-Generated Applications"));

  17.         LoadStdProfileSettings();  // Load standard INI file options (including MRU)

  18.         // Register the application's document templates.  Document templates
  19.         //  serve as the connection between documents, frame windows and views.

  20.         CMultiDocTemplate* pDocTemplate;
  21.         pDocTemplate = new CMultiDocTemplate(
  22.                 IDR_DEMOTYPE,
  23.                 RUNTIME_CLASS(CDemoDoc),
  24.                 RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  25.                 RUNTIME_CLASS(CDemoView));
  26.         AddDocTemplate(pDocTemplate);

  27.         // create main MDI Frame window
  28.         CMainFrame* pMainFrame = new CMainFrame;
  29.         if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  30.                 return FALSE;
  31.         m_pMainWnd = pMainFrame;

  32.         // Parse command line for standard shell commands, DDE, file open
  33.         CCommandLineInfo cmdInfo;
  34.         ParseCommandLine(cmdInfo);

  35.         cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

  36.         // Dispatch commands specified on the command line
  37.         if (!ProcessShellCommand(cmdInfo))
  38.         {
  39.                 return FALSE;
  40.         }

  41.         // The main window has been initialized, so show and update it.
  42.         pMainFrame->ShowWindow(m_nCmdShow);
  43.         pMainFrame->UpdateWindow();

  44.         return TRUE;
  45. }
复制代码
[MFC408]1[/MFC408]
[weixinlianxi]1[/weixinlianxi]






欢迎光临 工控编程吧 (https://www.gkbc8.com/) Powered by Discuz! X3.4