现在在编写一个编辑器,请问如何实现在一个编辑器实例已打开的情况下,在一个文件上右击鼠标打开时,能够在原实例中打开一个新的文档窗口。

解决方案 »

  1.   

    用CDocument 类的函数
    BOOL OnOpenDocument( LPCTSTR lpszPathName );
    将要打开的文件的绝对路径传给函数
      

  2.   

    首先你在用向导创建项目时要指定程序文档的专用扩展名,具体可以参考MSDN关于CMultiDocTemplate::CMultiDocTemplate 的帮助;其次程序必须设定为MDI风格,这样才能一次打开多个文档;再在CMyApp的InitInstance 函数中如下处理:
    BOOL CMyApp::InitInstance(){
      // ..........
      // ..........

      // Register the application's document templates.  Document templates
      //  serve as the connection between documents, frame windows and views.  CMultiDocTemplate* pDocTemplate;
      pDocTemplate = new CMultiDocTemplate(
        IDR_SIMPLETYPE,
        RUNTIME_CLASS(CSimplexDoc),
        RUNTIME_CLASS(CChildFrame), // custom MDI child frame
        RUNTIME_CLASS(CSimplexView));
      AddDocTemplate(pDocTemplate);  // create main MDI Frame window
      CMainFrame* pMainFrame = new CMainFrame;
      if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
        return FALSE;
      m_pMainWnd = pMainFrame;  // 允许支持文件拖放打开
      m_pMainWnd->DragAcceptFiles();  // 允许通过 DDE 消息打开文件
      EnableShellOpen();
      RegisterShellFileTypes(TRUE);  // 支持处理标准方法如 DDE, 打开命令等的命令行参数
      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);  // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
        return FALSE;  pMainFrame->ShowWindow(m_nCmdShow);
      pMainFrame->UpdateWindow();  return TRUE;
    }然后系统应该就能支持你的要求了!