📄 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 i;
CBrush* pNewBrush;
CBrush* pOldBrush;
//实体画刷的图案索引值
int nBrushPattern[6]=
{
HS_FDIAGONAL,
HS_BDIAGONAL,
HS_HORIZONTAL,
HS_DIAGCROSS,
HS_VERTICAL,
HS_CROSS,
};
//使用不同图案的实体画刷
for(i=0;i<6;i++)
{
//构造新画刷
pNewBrush=new CBrush;
if(pNewBrush->CreateHatchBrush(nBrushPattern[i],RGB(0,0,0)))
{
//选择新画刷
pOldBrush = pDC->SelectObject( pNewBrush );
//绘制矩形
pDC->Rectangle(140,20+i*60,400,50+i*60);
//恢复设备描述表中原有的画刷
pDC->SelectObject( pOldBrush );
}
//删除新画刷
delete pNewBrush;
}
//设置颜色表
struct tagColor
{
int r,g,b;
} color[7]=
{
{125,0,0},
{255,128,128},
{0,0,155},
{200,20,255},
{89,255,100},
{0,25,255},
{100,100,100},
};
//使用不同颜色的实体画刷
for(i=0;i<7;i++)
{
//构造新画刷
pNewBrush=new CBrush;
if( pNewBrush->CreateSolidBrush( RGB(color[i].r,color[i].g,color[i].b)))
{
//选择新画刷
pOldBrush = pDC->SelectObject( pNewBrush );
//绘制矩形
pDC->Ellipse(340,80+i*60,200,50+i*60);
//恢复设备描述表中原有的画刷
pDC->SelectObject( pOldBrush );
}
//删除新画刷
delete pNewBrush;
}
}
/////////////////////////////////////////////////////////////////////////////
// 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 + -