class CEx05aView : public CView
{
const CSize m_sizeEllipse; // 논리 단위
CPoint m_pointTopLeft; // 논리 단위, 원의 테두리 사각형의 좌측 상단 위치
CSize m_sizeOffset; // 디바이스 단위,
//점을 캡쳐하기 위한 좌측 상단으로부터의 크기
BOOL m_bCaptured;
/*
CRect m_rectEllipse;
int m_nColor; */
protected: // create from serialization only
CEx05aView();
...
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEx05aView)
...
virtual void OnInitialUpdate();
//}}AFX_VIRTUAL
...
// Generated message map functions
protected:
//{{AFX_MSG(CEx05aView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CEx05aView, CView)
//{{AFX_MSG_MAP(CEx05aView)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
...
CEx05aView::CEx05aView()
: m_sizeEllipse(100, -100), m_pointTopLeft(0, 0), m_sizeOffset(0, 0)
//: m_rectEllipse(0, 0, 4000, -4000)
{
// TODO: add construction code here
m_bCaptured = FALSE;
// m_nColor = GRAY_BRUSH;
}
...
void CEx05aView::OnDraw(CDC* pDC)
{
CEx05aDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CBrush brushHatch(HS_DIAGCROSS, RGB(255, 0, 0));
CPoint point(0, 0); // 논리 좌표 (0, 0)
pDC->LPtoDP(&point); // 장치 좌표에서,
pDC->SetBrushOrg(point); // 브러시를 윈도우 원점으로 정렬한다.
pDC->SelectObject(&brushHatch);
pDC->Ellipse(CRect(m_pointTopLeft, m_sizeEllipse));
pDC->SelectStockObject(BLACK_BRUSH); // brushHatch 선택 해제
/* pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse); */
}
...
void CEx05aView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CSize sizeTotal(800, 1050); // 8*10.5 인치
CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50);
SetScrollSizes(MM_LOENGLISH, sizeTotal, sizePage, sizeLine);
/*
CSize sizeTotal(20000, 30000); // 20x30 cm
CSize sizePage(sizeTotal.cx / 2, sizeTotal.cy / 2);
CSize sizeLine(sizeTotal.cx / 50, sizeTotal.cy / 50);
SetScrollSizes(MM_HIMETRIC, sizeTotal, sizePage, sizeLine);*/
/*
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE); */
}
void CEx05aView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
// {
// pDC->SetMapMode(MM_HIMETRIC);
// }
CView::OnPrepareDC(pDC, pInfo);
}
void CEx05aView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
OnPrepareDC(&dc);
// 논리 좌표
CRect rectEllipse(m_pointTopLeft, m_sizeEllipse);
dc.LPtoDP(rectEllipse); // 지금부터 디바이스 좌표이다
CRgn circle;
circle.CreateEllipticRgnIndirect(rectEllipse);
if (circle.PtInRegion(point)) {
// 마우스를 캡쳐하면 LButtonUp 메시지가 호출된다.
SetCapture();
m_bCaptured = TRUE;
CPoint pointTopLeft(m_pointTopLeft);
dc.LPtoDP(&pointTopLeft);
m_sizeOffset = point - pointTopLeft; // 디바이스 좌표
// 새로운 마우스 커서는 마우스가 캡쳐되어 있는 동안에
// 활성화 된다.
::SetCursor(::LoadCursor(NULL, IDC_CROSS));
}
/* CClientDC dc(this);
OnPrepareDC(&dc);
CRect rectDevice = m_rectEllipse;
dc.LPtoDP(rectDevice);
if (rectDevice.PtInRect(point)) {
if (m_nColor == GRAY_BRUSH){
m_nColor = WHITE_BRUSH;
}
else {
m_nColor = GRAY_BRUSH;
}
InvalidateRect(rectDevice);
}*/
// CScrollView::OnLButtonDown(nFlags, point);
}
void CEx05aView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bCaptured) {
CClientDC dc(this);
OnPrepareDC(&dc);
CRect rectOld(m_pointTopLeft, m_sizeEllipse);
dc.LPtoDP(rectOld);
InvalidateRect(rectOld, TRUE);
m_pointTopLeft = point - m_sizeOffset;
dc.DPtoLP(&m_pointTopLeft);
CRect rectNew(m_pointTopLeft, m_sizeEllipse);
dc.LPtoDP(rectNew);
InvalidateRect(rectNew, TRUE);
}
// CScrollView::OnMouseMove(nFlags, point);
}
void CEx05aView::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);
}