MFC中如何获得View指针

 我来答
一土厅0y
2013-01-08 · 超过40用户采纳过TA的回答
知道答主
回答量:50
采纳率:0%
帮助的人:9万
展开全部
对于SDI程序来说, 如果;CMainFrame中只有一个view的话, 那很好办, 直接用函数获得view指针即可,
先获得CFrameWnd指针, 方法是CMainFrame *pFrame = AfxGetMainWnd();
然后CView *pView = pFrame-GetAcitveView();就ok了
但有时候有多个view存在, 这时候获得view指针就会出问题了, 可以用如下方法:
应该是没有问题的
CView *GetView(){CWinApp *winApp = AfxGetApp();
if(winApp == NULL) return NULL;
CDocManager *pDocManager = winApp-m_pDocManager;
if(pDocManager == NULL) return NULL;
POSITION pos1 = pDocManager-GetFirstDocTemplatePosition();
while (pos1){CDocTemplate *pDocTemplate = pDocManager-GetNextDocTemplate(pos1);
if(pDocTemplate == NULL) continue;
POSITION pos2 = pDocTemplate-GetFirstDocPosition();
while (pos2){CDocument *pDoc = pDocTemplate-GetNextDoc(pos2);
if(pDoc == NULL) continue;
POSITION pos3 = pDoc-GetFirstViewPosition();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式