本文是对网络上各种资料进行了梳理,并在VisualC++6.0下进行了实验测试。
1. 在MFC多文档应用程序中同时显示两个视图,其中一个视图显示电路原理图,另外一个显示仿真结果。
2. 两个视图需要同时显示,但是并非分割显示,而是通过切换(切换功能尚未实现)
在多文档应用程序中,视图类是由CMultiDocTemplate来负责管理的。自动生成的MFC框架中在C**App类的InitInstance()函数中,有以下的语句:
2 pDocTemplate=
3
4
5
6
7
8
由于有两个视图需要显示,所以需要创建两个CMultiDocTemplate对象来管理,其中每个对象管理不同的View对象
为了方便在其他类中引用,我在C**App类中增
2
3
然后在InitInstance()函数替换原有创建CMultiDocTemplate对象指针的语句,这里我的代码是:
10
11
12
13
而此时就有了两个视图,而MFC应用程序默认是只打开一个视图的,所以这时运行程序就会出现一个要求选择显示哪个视图的对话框
为了自动显示,我们需要重写C**App类的OnFileNew()函数
2 {
3
4}
根据MSDN2001,需要在C**App类的消息响应中添加一句话才能使该函数被响应
2
3
4
5
6
7
注:MSDN2001:
CWinApp::OnFileNew
You must add an
ON_COMMAND( ID_FILE_NEW, OnFileNew )
statement to your
到目前为止,程序还只能显示一个view,另外一个view还没有被显示出来。
我们需要在C**Doc类中添加一些东西
在OnNewDocument()函数中我们添加如下
2 CreateNewWindow(p_app->m_pTemplateDataView,
然后添加成员函数:
10
11
12
13
14
15
16
17
18}
此时再运行则可以一下子显示两个view了,不是重叠的。但是原理图view显示不完整,因为不是全窗口大小。我把它设置了一下
在CChildFrame类中改写虚函数ActivateFrame(int nCmdShow) ,nCmdShow默认值就是-1
2 {
3
4
5
6
7
8
9}
这样显示的窗口就最大化了
后面会继续更新,补充用tab键或其它方法在两个视图之间切换
本文参考的网址和文档:
http://topic.csdn.net/u/20111019/09/b54b0574-162d-4f80-8209-660070ac3feb.html
http://hi.baidu.com/liyy011/blog/item/150ce08080b449d2bd3e1e19
http://topic.okbase.net/200612/2006122710/2831427.html
http://blog.csdn.net/zhuimengzh/article/details/6976011
MSDN2001
侯捷著,《深入浅出MFC》
http://www.cppblog.com/cs-xiaolee/archive/2011/12/01/161292.html