绘图基础--使用画笔和画刷绘制网络
// rect.cpp
#include <afxwin.h>
// Define the application class
class CApp : public CWinApp
{
public:
virtual BOOL InitInstance();
};
CApp App;
// define the window class
class CWindow : public CFrameWnd
{
public:
CWindow();
void OnPaint();
DECLARE_MESSAGE_MAP()
};
// The window's constructor
CWindow::CWindow()
{
Create(NULL, "Drawing Tests",
WS_OVERLAPPEDWINDOW,
CRect(0,0,500,400));
}
// The message map
BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )
ON_WM_PAINT()
END_MESSAGE_MAP()
// Handle exposures
void CWindow::OnPaint()
{
CRect rect;
GetClientRect( rect );
CPaintDC dc(this);
// 创建画笔(实线,2像素,蓝色)
CPen pen(PS_SOLID, 2, RGB(0,0,255)), *oldPen;
oldPen = dc.SelectObject(&pen);
// 创建画刷(水平和垂直网格,红色)
CBrush brush(HS_CROSS,RGB(255,0,0)), *oldBrush;
oldBrush = dc.SelectObject(&brush);
// 使用当前笔绘制矩形,用当前画刷填充
rect.InflateRect(-20, -20);
dc.Rectangle(rect);
// return old pen and brush
dc.SelectObject(oldPen);
dc.SelectObject(oldBrush);
}
// Init the application
BOOL CApp::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}