繪圖基礎--畫筆
// line2.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,300));
}
// The message map
BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )
ON_WM_PAINT()
END_MESSAGE_MAP()
// Handle exposure events
void CWindow::OnPaint()
{
CRect rect;
int x;
GetClientRect( rect );
CPaintDC dc(this);
// 創建畫筆(實線,2像素,藍色)
CPen pen(PS_SOLID, 2, RGB(0,0,255)), *oldPen;
oldPen = dc.SelectObject(&pen);
// 畫線
for (x=0; x<rect.Width(); x+=10)
{
dc.MoveTo(0,0);
dc.LineTo(x,rect.Height());
}
// Return old pen;
dc.SelectObject(oldPen);
}
// Init the application
BOOL CApp::InitInstance()
{
m_pMainWnd = new CWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}