PersonalCorpus 版 (精华区)
class CMyView
{
..........
public:
static CMyView* GetView();
.........
};
对单视图的实现
CMyView* CMyView::GetView()
{
CFrameWnd* pFrame = (CFrame*)(AfxGetApp()->m_pMainWnd);
CView* pView = pFrame->GetActiveView();
if(!pView)
return NULL;
if(!pView->IsKindOf(RUNTIME_CLASS(CMyView)))
return NULL;
return (CMyView*)pView;
}
对多文档的实现
CMyView* CMyView::GetView()
{
CMDIChildWnd* pChild =
((CMDIFrameWnd*)(AfxGetApp()->m_pMainWnd))->MDIGetActiveView();
if(!pView)
return NULL;
if(!pView->IsKindOf(RUNTIME_CLASS(CMyView)))
return NULL;
return (CMyView*)pView;
}
同样,对单视图,还可以用如下的方法:
#include "MyDoc.h"
#include "MyView.h"
extern CMyView* pView;
在MyView.cpp中
CMyView* pView;
CMyView::CMyview()
{
pView = this;
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.093毫秒