- 0
- 0
- 约8.55千字
- 约 7页
- 2018-04-23 发布于福建
- 举报
章 画笔和画刷
07章 画笔和画刷
画笔和画刷是作图的基础,本章介绍的是静态的描画,下一章介绍用鼠标动态地作画。
一、画笔的种类和使用方法
画笔的使用和上一章的字体类似,首先用CreatePen()函数创建一个画笔对象,然后与设备文本绑定,同时得到旧的画笔。用完后删除新画笔,并且恢复旧画笔。画笔的种类有7种,参照下表及下面的例子。
值 说明 PS_SOLID 实线 PS_DASH 破折线(只有宽度为1,或小于等于设备的基本象素时有效) PS_DOT 点(只有宽度为1,或小于等于设备的基本象素时有效) PS_DASHDOT 实线和点间隔(只有宽度为1,或小于等于设备的基本象素时有效) PS_DASHDOTDOT 实线和点和点间隔(只有宽度为1,或小于等于设备的基本象素时有效) PS_NULL 不显示线 PS_INSIDEFRAME The pen is solid. When this pen is used in any GDI drawing function that takes a bounding rectangle, the dimensions of the figure are shrunk so that it fits entirely in the bounding rectangle, taking into account the width of the pen. This applies only to geometric pens. VC中并不提供指定2点画线的功能,LineTo()函数从上一次画笔所在位置作为起点,一直画到LineTo()函数指定位置终止。如果要从指定位置画到另一指定位置这就需要用到MoveToEx()函数。MoveToEx()函数只移动画笔的位置,并不画线。
BOOL MoveToEx( BOOL LineTo( HPEN CreatePen(
HDC hdc, //HDC HDC hdc, //HDC int fnPenStyle, //画笔类型
int X, //x座标 int X, //x座标 int nWidth, //画笔宽度
int Y, //y座标 int Y, //y座标 COLORREF crColor //画笔颜色
LPPOINT lpPoint //返回先前位置 ); );
);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{;
HDC hdc;
HPEN hNewPen, hOldPen;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, ps);
hNewPen = CreatePen(PS_SOLID,1,0x0000FF);
hOldPen = (HPEN)SelectObject(hdc, hNewPen);
MoveToEx(hdc, 10, 10, NULL);
LineTo(hdc, 200, 10);
DeleteObject(hNewPen);
hNewPen = CreatePen(PS_DASH,1,0x00FF00);
SelectObject(hdc, hNewPen);
MoveToEx(hdc, 10, 20, NULL);
LineTo(hdc, 200, 20);
DeleteObject(hNewPen);
hNewPen = CreatePen(PS_DOT,1,0xFFFF00);
SelectObject(hdc, hNewPen);
Move
原创力文档

文档评论(0)