我在一个函数里放下列语句,为什么不能成功???
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CMYView* pView=(CMYView*)pFrame->GetActiveView();
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();
我想在文档类外引用文档对象中的成员,怎么实现???
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CMYView* pView=(CMYView*)pFrame->GetActiveView();
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();
我想在文档类外引用文档对象中的成员,怎么实现???
需要在MainFrm.cpp中#include "XXView.h"
#include "XXDoc.h"
在XXview.h中#include "XXDoc.h"1.若在视类中得到文档类成员
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();
pDoc->yourdata;
2.若不再视类中,在框架类中先获得视类指针
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
CMYView* pView=(CMYView*)pFrame->GetActiveView();
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();
CMainFrame * pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd);
CMyDoc * pDoc = pMainWnd->GetActiveDocument();多文档框架下:
CMainFrame* pFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
CMYView* pView=(CMYView*)pFrame->GetActiveView();
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();
好象在Frame-doc-view框架之外的地方是不能用上述代码引用框架内的内容的吧?!
最后我是通过全局变量解决了该问题的!!!
在下感谢各位高手提点!!!
单文档框架下:
CMainFrame * pMainWnd = (CMainFrame *)(AfxGetApp()->m_pMainWnd);
CMyDoc * pDoc = pMainWnd->GetActiveDocument();多文档框架下:
CMainFrame* pFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
CMYView* pView=(CMYView*)pFrame->GetActiveView();
CMYDoc* pDoc=(CMYDoc*)pView->GetDocument();