📄 ch9demo7view.cpp
字号:
// Ch9Demo7View.cpp : implementation of the CCh9Demo7View class
//
#include "stdafx.h"
#include "Ch9Demo7.h"
#include "Ch9Demo7Doc.h"
#include "Ch9Demo7View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View
IMPLEMENT_DYNCREATE(CCh9Demo7View, CView)
BEGIN_MESSAGE_MAP(CCh9Demo7View, CView)
//{{AFX_MSG_MAP(CCh9Demo7View)
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View construction/destruction
CCh9Demo7View::CCh9Demo7View()
{
// TODO: add construction code here
rgnA.CreateRectRgn(0,0,400,400); //创建初始对象,任意值均可
rgnB.CreateRectRgn(0,0,400,400); //创建初始对象,任意值均可
}
CCh9Demo7View::~CCh9Demo7View()
{
}
BOOL CCh9Demo7View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View drawing
void CCh9Demo7View::OnDraw(CDC* pDC)
{
CCh9Demo7Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRgn rgn1,rgn2; //构造CRgn对象
CPoint pts[]={CPoint(190, 90),CPoint(370, 40), CPoint(210, 300), CPoint(100, 30)};
rgn1.CreatePolygonRgn(pts,4,ALTERNATE ); //绘制多端折线
rgn2.CreateEllipticRgn(120,25,190,300); //椭圆区域
rgnA.CombineRgn(&rgn1,&rgn2,RGN_AND); //交集
rgnB.CombineRgn(&rgn1,&rgn2,RGN_XOR); //交集以外的区域
CBrush brush,brush2;
brush.CreateSolidBrush(RGB(255,0,0)); //创建画刷
pDC->FillRgn(&rgnA,&brush);//用画刷填充区域
brush2.CreateHatchBrush(HS_DIAGCROSS,RGB(128,0,128)); //创建画刷
pDC->FillRgn(&rgnB,&brush2);//用画刷填充区域
brush.DeleteObject();//删除画刷
brush2.DeleteObject();//删除画刷
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View printing
BOOL CCh9Demo7View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCh9Demo7View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCh9Demo7View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View diagnostics
#ifdef _DEBUG
void CCh9Demo7View::AssertValid() const
{
CView::AssertValid();
}
void CCh9Demo7View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCh9Demo7Doc* CCh9Demo7View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh9Demo7Doc)));
return (CCh9Demo7Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCh9Demo7View message handlers
void CCh9Demo7View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (rgnA.PtInRegion(point))//鼠标位置在区域A中
{
AfxMessageBox("用户击中了两个图形的交集!");
}
if (rgnB.PtInRegion(point))//鼠标位置在区域B中
{
AfxMessageBox("用户击中了两个图形的交集以外的区域!");
}
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -