home *** CD-ROM | disk | FTP | other *** search
- // MiniDrVw.cpp : implementation of the CMiniDrawView class
- //
-
- #include "stdafx.h"
- #include "MiniDraw.h"
-
- #include "MiniDDoc.h"
- #include "MiniDrVw.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView
-
- IMPLEMENT_DYNCREATE(CMiniDrawView, CView)
-
- BEGIN_MESSAGE_MAP(CMiniDrawView, CView)
- //{{AFX_MSG_MAP(CMiniDrawView)
- ON_WM_LBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONUP()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView construction/destruction
-
- CMiniDrawView::CMiniDrawView()
- {
- // TODO: add construction code here
-
- m_Dragging = 0;
- m_HCross = AfxGetApp ()->LoadStandardCursor (IDC_CROSS);
- }
-
- CMiniDrawView::~CMiniDrawView()
- {
- }
-
- BOOL CMiniDrawView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- m_ClassName = AfxRegisterWndClass
- (CS_HREDRAW | CS_VREDRAW, // class styles
- 0, // no cursor
- (HBRUSH)::GetStockObject (WHITE_BRUSH), // assign white background brush
- 0); // no icon
- cs.lpszClass = m_ClassName;
-
- return CView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView drawing
-
- void CMiniDrawView::OnDraw(CDC* pDC)
- {
- CMiniDrawDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView diagnostics
-
- #ifdef _DEBUG
- void CMiniDrawView::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CMiniDrawView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CMiniDrawDoc* CMiniDrawView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniDrawDoc)));
- return (CMiniDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMiniDrawView message handlers
-
- void CMiniDrawView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- m_PointOrigin = point;
- m_PointOld = point;
- SetCapture ();
- m_Dragging = 1;
-
- RECT Rect;
- GetClientRect (&Rect);
- ClientToScreen (&Rect);
- ::ClipCursor (&Rect);
-
- CView::OnLButtonDown(nFlags, point);
- }
-
- void CMiniDrawView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- ::SetCursor (m_HCross);
-
- if (m_Dragging)
- {
- CClientDC ClientDC (this);
- ClientDC.SetROP2 (R2_NOT);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (m_PointOld);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (point);
- m_PointOld = point;
- }
-
- CView::OnMouseMove(nFlags, point);
- }
-
- void CMiniDrawView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- if (m_Dragging)
- {
- m_Dragging = 0;
- ::ReleaseCapture ();
- ::ClipCursor (NULL);
- CClientDC ClientDC (this);
- ClientDC.SetROP2 (R2_NOT);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (m_PointOld);
- ClientDC.SetROP2 (R2_COPYPEN);
- ClientDC.MoveTo (m_PointOrigin);
- ClientDC.LineTo (point);
- }
-
- CView::OnLButtonUp(nFlags, point);
- }
-