//shape the CPP: implementation of the CMyView class
//
# include "stdafx. H"
# include "shape. H
"
# include "shape Doc. H"
# include "shape the h
"
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif
/////////////////////////////////////////////////////////////////////////////
//CMyView
IMPLEMENT_DYNCREATE (CMyView, CView)
BEGIN_MESSAGE_MAP (CMyView, CView)
//{{AFX_MSG_MAP (CMyView)
ON_COMMAND (ID_CIRCLE OnCircle)
ON_COMMAND (ID_HAND OnHand)
ON_COMMAND (ID_RECT OnRect)
ON_WM_LBUTTONDOWN ()
ON_WM_LBUTTONUP ()
ON_WM_MOUSEMOVE ()
//}} AFX_MSG_MAP
//Standard printing commands
ON_COMMAND (ID_FILE_PRINT, CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_DIRECT, CView: : OnFilePrint)
ON_COMMAND (ID_FILE_PRINT_PREVIEW, CView: : OnFilePrintPreview)
END_MESSAGE_MAP ()
/////////////////////////////////////////////////////////////////////////////
//CMyView construction/destruction
CMyView: : CMyView ()
{
//TODO: add construction code here
M_hand=m_circle=m_rect=false;
}
CMyView: : ~ CMyView ()
{
}
BOOL CMyView: : PreCreateWindow (CREATESTRUCT& Cs)
{
//TODO: Modify the Window class or styles here by modifying the
//the CREATESTRUCT cs
Return the CView: : PreCreateWindow (cs);
}
/////////////////////////////////////////////////////////////////////////////
//CMyView drawing
Void CMyView: : ontouch * pDC (CDC)
{
CMyDoc * pDoc=GetDocument ();
ASSERT_VALID (pDoc);
//TODO: add the draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
//CMyView printing
BOOL CMyView: : OnPreparePrinting (CPrintInfo * pInfo)
{
//the default preparation
Return DoPreparePrinting (pInfo);
}
Void CMyView: : OnBeginPrinting (CDC, pDC */* */pInfo CPrintInfo */* */)
{
//TODO: add extra initialization before printing
}
Void CMyView: : OnEndPrinting (CDC, pDC */* */pInfo CPrintInfo */* */)
{
//TODO: add the cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
//CMyView diagnostics
# ifdef _DEBUG
Void CMyView: : AssertValid (const)
{
The CView: : AssertValid ();
}
Void CMyView: : Dump (CDumpContext& Dc) const
{
The CView: : Dump (dc);
}
CMyView CMyDoc * : : GetDocument ()//non - the debug version is the inline
{
ASSERT (m_pDocument - & gt; IsKindOf (RUNTIME_CLASS (CMyDoc)));
Return (CMyDoc *) m_pDocument;
}
# endif//_DEBUG
/////////////////////////////////////////////////////////////////////////////
//CMyView message handlers
Void CMyView: : OnCircle ()
{
//TODO: Add your command handler code here
M_circle=true;
M_rect=m_hand=false;
}
Void CMyView: : OnHand ()
{
//TODO: Add your command handler code here
M_hand=true;
M_circle=m_rect=false;
}
Void CMyView: : OnRect ()
{
//TODO: Add your command handler code here
M_rect=true;
M_circle=m_hand=false;
}
Void CMyView: : OnLButtonDown (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
If (m_hand)
{
SPT=point;
}
If (m_circle | | m_rect)
{
SetCapture ();
SPT=point;
Ept=point;
}
The CView: : OnLButtonDown (nFlags, point);
}
Void CMyView: : OnLButtonUp (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
ReleaseCapture ();
The CView: : OnLButtonUp (nFlags, point);
}
Void CMyView: : onm ouseMove (UINT nFlags, CPoint point)
{
//TODO: Add your message handler code here and/or call the default
The CDC * pDC=GetDC ();
If (m_hand & amp; & (nFlags& & MK_LBUTTON))
{
PDC - & gt; MoveTo (SPT);
PDC - & gt; The LineTo (point);
SPT=point;
}
If (m_rect & amp; & (nFlags& & MK_LBUTTON))
{
Old CGdiObject *=pDC - & gt; SelectStockObject (NULL_BRUSH);
Int drawmode=pDC - & gt; GetROP2 ();//save the original drawing mode
PDC - & gt; SetROP2 (R2_NOTCOPYPEN);//set the new drawing mode
PDC - & gt; A Rectangle (ept) x, ept. J y, SPT. X, SPT. Y);
PDC - & gt; SetROP2 (drawmode);
PDC - & gt; A Rectangle (SPT) x, SPT. J y, point, x, point, y);
PDC - & gt; SelectObject (old);
Ept=point;
}
If (m_circle & amp; & (nFlags& & MK_LBUTTON))
{
Old CGdiObject *=pDC - & gt; SelectStockObject (NULL_BRUSH);
Int drawmode=pDC - & gt; GetROP2 ();//save the original drawing mode
PDC - & gt; SetROP2 (R2_NOTCOPYPEN);//set the new drawing mode
PDC - & gt; The Ellipse (ept) x, ept. J y, SPT. X, SPT, y);
PDC - & gt; SetROP2 (drawmode);
PDC - & gt; The Ellipse (SPT) x, SPT. J y, point, x, point, y);
PDC - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull