图元基类 class CDrawObj: public CObject ∥ Attributes CDrawDoc*m pDocument;//owner virtual int GetHandle) virtual CPoint Get Handle(int nHandle) virtual HCURSOR Get Handle Cursor(int n Handle virtual void SetLine Color(COLORREF color) virtual void Set Fill Color(COLORREF color) ∥ Operations virtual void Draw(CDC pDC) virtual void Draw Tracker(CDC* pDC, Tracker State state) virtual void Move To(const CRect& positon, CDraw View"pView= NULL); virtual int HitTest( CPoint point, CDraw View*pView, BOOL bSelected); virtual BOOL Intersects( const CRect& rect) virtual void Move HandleTo(int nHandle, CPoint point, CDraw View*p View=NULL) virtual void OnOpen( CDraw View* p View) virtual void OnEditPropertiesO virtual CDrawObj* Clone( CDraw Doc* p= NULL) virtual void Removel virtual void Serialize( CArchive& ar) };
! " ! #$% $ ! %& & $$'(! %( & $$'(! ! )* +)*%! ,) $-+ . . /0#&&! ) "+ . . +1 &%! 1 &2 $-! ,) +"+ . . /0#&&! . . ! '" ! /0#&&! $ ! %3 4-! 55 6
图元层次结构 CDrawObj CDrawobj CDrawRect CDrawPoly CDrawDleobj cDrawRect CDrawPoly CDrawsspt-
"# $ %& "# '' CDrawObj CDrawRect CDrawPoly CDrawOleObj ……
图元的创建 永久支持: CDocument: Serialize->CObList. Serialize cObject. Serialize CDrawObj: Clone Draw tool:创建图元对象
./01 "# ( *+!"
交互操作 键盘和菜单侖令 MFC内部机制 鼠标操作 在 CDraw View的鼠标处理函数中处理 工具箱:工具链,有一个当前活动工具 转交给当前活动工具来处理
23,4567 89() !"#$% &'(#$%)
工具箱和 CDraw tool class CDraw Tool ∥ Constructors p CDraw Tool ( Draw Shape n DrawShape) ∥ Overridable virtual void OnLButton Down( CDraw View* pView, UINT nFlags, const CPoint& point) virtual void OnLButtonDblClk(CDraw View*pView, UINT nFlags, const CPoint& point) virtual void OnLButtonUp(CDraw View* pView, UINT nFlags, const CPoint& point virtual void On MouseMove( CDraw View* pView, UINT n Flags, const CPoint& point virtual void OnEditProperties( CDraw View'pView) virtual void On Cancell ∥ Attributes Draw Shape m draw Shape static CDraw Tool* FindTool(Draw Shape drawShape) static CPtrList c tools static Draw Shape c draw Shape
) ) %4 %4! &1 . . +#20)(7+"-! &1* . . +#20)(7+"-! &1# . . +#20)(7+"-! ,, . . +#20)(7+"-! '" . . ! ! %4 %4 )() %4 %4! "& %4 %4 55 6