本文主要介绍:MFC中一些基础知识,包括文档类Doc和视图类View指针的获取,逻辑坐标与设备坐标及其转化和OnDraw函数。
一、获取Doc类和View类指针:
1.添加头文件:
#include "MainFrm.h"
#include "C***Doc.h" //Doc类头文件要放在View类头文件前面
#include "C***View.h"
2.单文档中获取:
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
C***Doc *pDoc = (C***Doc*)pFrame->GetActiveDocument(); //获取文档类
C***View* pView = (C***View*)pFrame->GetActiveView(); //获取视图类
//或
CMainFrame* pFrame=(CMaimFrame*)AfxGetApp()->m_pMainWnd;
C***Doc *pDoc = (C***Doc*)pFrame->GetActiveDocument(); //获取文档类
C***View* pView = (C***View*)pFrame->GetActiveView(); //获取视图类<pre name="code" class="cpp">
3.多问档中获取:
//获得文档类指针
CMDIFrameWnd *pFrame = (