将文件打开到MFC SDI应用程序的右侧视图中 [英] opening file into right-hand view of MFC SDI app

查看:84
本文介绍了将文件打开到MFC SDI应用程序的右侧视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个mfc sdi APP.
文件的负载显示在左侧的树视图中.该树形视图是从文档填充的,该文档列出了文件和文件夹及其层次结构.

现在,我想右键单击一个文件,然后选择一个弹出菜单选项以将文件打开到右侧窗格中.我可以单击鼠标右键并弹出菜单.但是,填充树视图的文档与打开到右侧窗格的文档不同.

通过将从树视图中选择的文件的路径直接传递到CRightHandView类中,然后读取文件并调用SetWindowText,可以完成此操作.它可以工作,但是我不确定我是否按预期的方式使用MFC框架.

I have an mfc sdi APP.
A load of files are shown in the tree-view on the left. This tree-view is populated from the document, which lists files and folders with their hierarchy.

Now, I want to right-click on a file and select a pop-up menu option to open the file into the right-hand pane. I can do the right-click and pop-up menu bit. However, the document that populates the tree-view is not the same document that opens into the right-hand pane.

I have done this by just passing the path of the file selected from the tree view straight into the CRightHandView class and reading the file and calling SetWindowText. It works but I am not sure I am using MFC framework in the way it is intended. Is there a more correct or elegant way?

推荐答案

这是我使用MFC的一段时间,但是在我回忆模型时,应该将CView连接到CDocument(ClassWizard为您完成).然后,当用户请求打开文件时,CDocument类应处理该文件并将其读入内存,然后调用关联的CView类以所需的任何方式显示数据.这也允许文档被更新,然后发信号通知任何连接的视图以更新其显示.可能仍然有一些有关此示例的MFC教程.
It''s a while since I used MFC but as I recall the model, you should connect the CView to a CDocument (ClassWizard does it for you). Then when the user requests a file to be opened, the CDocument class should handle it and read it into memory and then call the associated CView class to display the data in whatever way is necessary. This also allows for the document to be updated and then signal any connected views to update their displays. There are probably still some MFC tutorials around with examples of this.


如果您使用的是SDI,那么根据定义,此时只能有一个打开的文档.
听起来您的设计概念是正确的.树形视图表示文档,右侧视图可以是任何内容-在树形视图中选择项目时,可以根据需要有效地打开文件.
如果您需要在正确的视图中进行一些编辑(不确定是否必须这样做),那么您将必须使用自己的自定义处理程序来进行这些操作,因为内置的序列化机制仅有助于更改树形视图.
我认为一切都很好.
If you are using SDI, by definition there can only be one open document at the time.
Sounds like your design concept is correct. Tree view represents the document, the right side view can be anything - effectively files are opened as necessary, as items get selected in the tree view.
If you need to do some editing in the right view (not sure if you have to), then you will have to use your own customized handlers for these operations as your in-built serialization mechanism will only help with changes in the tree view.
All good I think.


这篇关于将文件打开到MFC SDI应用程序的右侧视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆