MFC MDI 选项卡式应用程序 - 想要将非文档窗口添加到选项卡组

发布于 2024-10-17 13:23:20 字数 942 浏览 6 评论 0原文

我有一个在 Visual Studio 中开发的具有选项卡式界面的 MFC MDI 应用程序。我想在选项卡组中打开非文档视图的视图 - 即它们没有关联的文档,无需保存它们等。在某种程度上,它们的行为类似于非模式对话框,但带有选项卡。 [这些窗口只是为了显示信息和接受命令]

MDI 应用程序的内部机制似乎非常适合使用 DocTemplate – 文档 – 框架 – 视图对象结构及其关联的窗口。

Q1) 有人知道如何创建此类窗口并将它们添加到已经建立的 MDI 选项卡组中吗?我尝试创建一个 RichEdit 窗口并将其添加到其中:

 // m_wndListingView will be a non-editable CRichEditCtrl

 m_wndListingView->Create(WS_CHILD | WS_VISIBLE | ES_WANTRETURN | WS_VSCROLL |
   WS_HSCROLL | ES_MULTILINE | ES_LEFT | ES_AUTOHSCROLL | ES_SAVESEL |ES_READONLY,
   CRect(0, 0, 20, 20), pMainFrame, 1234);

 // get Tab control and add a new tab

 CMFCTabCtrl    *mm_wndTabCtrl = &pMainFrame->GetMDITabs();
 mm_wndTabCtrl->AddTab (m_wndListingView, _T("LISTING"));

这创建并显示了窗口..但它没有添加到选项卡组中。

Q2)如果我设法在选项卡组中正确显示一个窗口(也许它需要是一个框架窗口),我如何告诉“系统”当用户关闭它时,我不希望应用程序提示用户保存文档?也许我可以重载“OnClose”方法...但它不能是 document::OnClose(),因为没有文档。

感谢您的任何想法, 中科院

I have an MFC MDI application I've developed in Visual Studio with a tabbed interface. I would like to open views in the tab group that are non-document views – i.e. they have no associated document, no need to save them, etc. In a way they would behave like a non-modal dialog, but tabbed. [These windows are simply to display information and take commands]

The internal machinery of the MDI apps seems very geared toward working with the DocTemplate – Document – Frame – View object structures along with their associated windows.

Q1) Anybody got any ideas on how to create such windows and add them into the already-established MDI tab group? I’ve tried to create a RichEdit window and added it in, with:

 // m_wndListingView will be a non-editable CRichEditCtrl

 m_wndListingView->Create(WS_CHILD | WS_VISIBLE | ES_WANTRETURN | WS_VSCROLL |
   WS_HSCROLL | ES_MULTILINE | ES_LEFT | ES_AUTOHSCROLL | ES_SAVESEL |ES_READONLY,
   CRect(0, 0, 20, 20), pMainFrame, 1234);

 // get Tab control and add a new tab

 CMFCTabCtrl    *mm_wndTabCtrl = &pMainFrame->GetMDITabs();
 mm_wndTabCtrl->AddTab (m_wndListingView, _T("LISTING"));

This created and displayed the window .. but it was not added to the tab group.

Q2) If I managed to get a window (perhaps it needs to be a frame window) displayed properly in the tab group, how do I tell the ‘system’ that when the user closes it, I do not want the app to prompt the user to Save the document ? Perhaps I can overload an 'OnClose' method ... but it can't be document::OnClose(), because there is no document.

Thanks for any ideas,
CAS

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阿楠 2024-10-24 13:23:20

您需要创建一个框架和视图来托管丰富的编辑。这可以在没有文档的情况下完成。该视图将是 richedit 的父视图(而不是 pMainFrame)。

沿着这些思路(警告,未经测试):

        CFrame* pFrame = (Crame*)RUNTIME_CLASS( CFrame )->CreateObject();
        CCreateContext context;
        context.m_pNewViewClass = RUNTIME_CLASS( CView );
        context.m_pCurrentDoc = NULL;
        context.m_pCurrentFrame = NULL;
        context.m_pLastView = NULL;
        context.m_pNewDocTemplate = NULL;

        // NOTE: create IDR_SOMERESOURCE string (for tab title), menu, etc as needed
        BOOL frameLoaded = pFrame->LoadFrame( IDR_SOMERESOURCE, WS_OVERLAPPEDWINDOW, pMainFrame, &context );
        if (frameLoaded)
            Frame->InitialUpdateFrame( NULL, TRUE );

           // now create your rich edit with the view as its parent

You need to create a frame and view on which to host your rich edit. This can be done without a document. The view will be the parent of the richedit (rather than pMainFrame).

Something along these lines (warning, untested):

        CFrame* pFrame = (Crame*)RUNTIME_CLASS( CFrame )->CreateObject();
        CCreateContext context;
        context.m_pNewViewClass = RUNTIME_CLASS( CView );
        context.m_pCurrentDoc = NULL;
        context.m_pCurrentFrame = NULL;
        context.m_pLastView = NULL;
        context.m_pNewDocTemplate = NULL;

        // NOTE: create IDR_SOMERESOURCE string (for tab title), menu, etc as needed
        BOOL frameLoaded = pFrame->LoadFrame( IDR_SOMERESOURCE, WS_OVERLAPPEDWINDOW, pMainFrame, &context );
        if (frameLoaded)
            Frame->InitialUpdateFrame( NULL, TRUE );

           // now create your rich edit with the view as its parent
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文