如果需要在CDialog类中使用View类的成员变量,有以下方法可以实现(以CSceneView为例):
方法一(使用全局变量):
如下:
1. 在Dialog1.h中class CDialog定义之前,加上:extern CSceneView* pView;
2. 在Dialog1.h中包含头文件:#include "SceneDoc.h"和#include "SceneView.h"
3. 在Dialog.cpp中class CDialog实现之前,加上: CSceneView* pView;
4. 在SceneView.cpp中包含Dialog类的头文件:#include "Dialog1.h"
5. 在CSceneView类的构造函数中加入:pView=this;
方法二(直接定义View类的指针)
如下:
1. 在SceneView.h中将构造函数的属性由protected改为public
2. 在Dialog1.h中包含头文件:#include "SceneDoc.h"和#include "SceneView.h"
3. 在Dialog1.h定义public成员变量CSceneView* pView;
4. 在CDialog类的构造函数中加入pView=new CSceneView;或pView=new CSceneView();