📄 testbrushview.cpp
字号:
// TestBrushView.cpp : implementation of the CTestBrushView class
//
#include "stdafx.h"
#include "TestBrush.h"
#include "TestBrushDoc.h"
#include "TestBrushView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView
IMPLEMENT_DYNCREATE(CTestBrushView, CView)
BEGIN_MESSAGE_MAP(CTestBrushView, CView)
//{{AFX_MSG_MAP(CTestBrushView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView construction/destruction
CTestBrushView::CTestBrushView()
{
// TODO: add construction code here
}
CTestBrushView::~CTestBrushView()
{
}
BOOL CTestBrushView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView drawing
void CTestBrushView::OnDraw(CDC* pDC)
{
CTestBrushDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int nBrushPattern[6]= //阴影线模式画刷的图案索引值
{
HS_BDIAGONAL, //右下45度对角线
HS_CROSS, //十字交叉线
HS_DIAGCROSS, //45度十字交叉线
HS_FDIAGONAL, //右上45度对角线
HS_HORIZONTAL, //水平线
HS_VERTICAL, //垂直线
};
pDC->TextOut(0, 20, "阴影画刷");
//创建阴影线模式画刷
for(int i=0;i<6;i++)
{
//第一步:构造新画刷
CBrush NewBrush1(nBrushPattern[i],RGB(0,0,255));
//第二步:将新画刷选入设备环境中
CBrush * pOldBrush = pDC->SelectObject( &NewBrush1 );
//绘制矩形
pDC->Rectangle(100,20+i*60,600,70+i*60);
//第三步:恢复设备环境中原有的画刷
pDC->SelectObject( pOldBrush );
}
pDC->TextOut(0, 20+6*60, "实体画刷");
//创建一支红色实体模式画刷
CBrush NewBrush2(RGB(255,0,0));
//将新画刷选入设备环境中
CBrush * pOldBrush = pDC->SelectObject( &NewBrush2 );
//绘制矩形
pDC->Rectangle(100,20+6*60,600,70+6*60);
//恢复设备环境中原有的画刷
pDC->SelectObject( pOldBrush );
}
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView printing
BOOL CTestBrushView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestBrushView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestBrushView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView diagnostics
#ifdef _DEBUG
void CTestBrushView::AssertValid() const
{
CView::AssertValid();
}
void CTestBrushView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestBrushDoc* CTestBrushView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestBrushDoc)));
return (CTestBrushDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestBrushView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -