【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“MoveSelObView.cpp”一文,供大家参考学习
// MoveSelObView.cpp : implementation of the CMoveSelObView class
//
#include "stdafx.h"
#include "MoveSelOb.h"
#include "MoveSelObDoc.h"
#include "MoveSelObView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView
IMPLEMENT_DYNCREATE(CMoveSelObView, CScrollView)
BEGIN_MESSAGE_MAP(CMoveSelObView, CScrollView)
//{{AFX_MSG_MAP(CMoveSelObView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView construction/destruction
CMoveSelObView::CMoveSelObView() : m_sizeEllipse(100, -100),
m_pointTopLeft(0, 0),
m_sizeOffset(0, 0)
{
m_bCaptured = FALSE;
}
CMoveSelObView::~CMoveSelObView()
{
}
BOOL CMoveSelObView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView drawing
void CMoveSelObView::OnDraw(CDC* pDC)
{
CMoveSelObDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//创建红色画刷
CBrush brushHatch(HS_DIAGCROSS, RGB(255, 0, 0));
CPoint point(0, 0);
//转换逻辑坐标到设备坐标
pDC->LPtoDP(&point);
pDC->SetBrushOrg(point);
CBrush* pOldBrush = pDC->SelectObject(&brushHatch);
//画红色圆圈
pDC->Ellipse(CRect(m_pointTopLeft, m_sizeEllipse));
pDC->SelectObject(pOldBrush);
// TODO: add draw code for native data here
}
void CMoveSelObView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
//设置滚动范围
CSize sizeTotal(800, 1050); // 8-by-10.5 inches
CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50);
SetScrollSizes(MM_LOENGLISH, sizeTotal, sizePage, sizeLine);
}
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView printing
BOOL CMoveSelObView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMoveSelObView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMoveSelObView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView diagnostics
#ifdef _DEBUG
void CMoveSelObView::AssertValid() const
{
CScrollView::AssertValid();
}
void CMoveSelObView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CMoveSelObDoc* CMoveSelObView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMoveSelObDoc)));
return (CMoveSelObDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMoveSelObView message handlers
void CMoveSelObView::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rectEllipse(m_pointTopLeft, m_sizeEllipse);
CRgn circle;
CClientDC dc(this);
OnPrepareDC(&dc);
dc.LPtoDP(rectEllipse);
circle.CreateEllipticRgnIndirect(rectEllipse);
if (circle.PtInRegion(point)) {
//捕捉鼠标
SetCapture();
m_bCaptured = TRUE;
CPoint pointTopLeft(m_pointTopLeft);
dc.LPtoDP(&pointTopLeft);
m_sizeOffset = point - pointTopLeft;
//设置光标形状为十字状
::SetCursor(::LoadCursor(NULL, IDC_CROSS));
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CMoveSelObView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bCaptured) {
//释放鼠标捕捉
::ReleaseCapture();
m_bCaptured = FALSE;
}
CScrollView::OnLButtonUp(nFlags, point);
}
void CMoveSelObView::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_bCaptured) {
//如果有图形被选中,