【文章內(nèi)容簡介】
18 ? At this point, we simply need to know that there’re predefined windows message and user defined message which will respond to different events. ? Visual C++ provides a tool ClassWizard to help us make this job easier. Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 19 ? Let’s look at the project ex04a to learn more about the view class. save the view state initialize the view class data member Know MFC class such as CPoint, CRect, CSize, CRgn….. understand the window’s client area use MFC function to test if a point inside a region Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 20 ? // : interface of the CEx04aView class // ///////////////////////////////////////////////////////////////////////////// class CEx04aView : public CView { protected: // create from serialization only CEx04aView()。 DECLARE_DYNCREATE(CEx04aView) // Attributes public: CEx04aDoc* GetDocument()。 Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 21 ? // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CEx04aView) public: virtual void OnDraw(CDC* pDC)。 // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCTamp。 cs)。 protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo)。 virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)。 virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)。 //}}AFX_VIRTUAL Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 22 ? // Implementation public: virtual ~CEx04aView()。 ifdef _DEBUG virtual void AssertValid() const。 virtual void Dump(CDumpContextamp。 dc) const。 endif protected: // Generated message map functions protected: //{{AFX_MSG(CEx04aView) afx_msg void OnLButtonDown(UINT nFlags, CPoint point)。 //}}AFX_MSG DECLARE_MESSAGE_MAP() Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 23 ? private: int m_nColor。 CRect m_rectEllipse。 }。 ifndef _DEBUG // debug version in inline CEx04aDoc* CEx04aView::GetDocument() { return (CEx04aDoc*)m_pDocument。 } endif Chapter 4 Basic Event Handling, Mapping Modes and a Scrolling View VC++ Programming @ UESTC 24 ? //////////////////////////////////////////////////////////////////////////// // IMPLEMENT_DYNCREATE(CEx04aView, CView) BEGIN_MESSAGE_MAP(CEx04aView, CView) //{{AFX_MSG_MAP(CEx04aView) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP // Standard pr