VB中的GDI编程-2 画笔

画笔对象

画笔对象Pen用于在设备环境DC上绘制形状的轮廓线,比如矩形、圆及多边形等,形状的轮廓有线条类型、粗细及颜色三个属性,我们都需要在Pen对象进行体现。在GDI的API函数中,操作画笔时,我们有以下比较常用的函数:

1 Public Declare Function CreatePen Lib "gdi32" Alias "CreatePen" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
2 Public Declare Function CreatePenIndirect Lib "gdi32" Alias "CreatePenIndirect" (lpLogPen As LOGPEN) As Long
3 Public Declare Function ExtCreatePen Lib "gdi32" Alias "ExtCreatePen" (ByVal dwPenStyle As Long, ByVal dwWidth As Long, lplb As LOGBRUSH, ByVal dwStyleCount As Long, lpStyle As Long) As Long
4 Public Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Long, ByVal hObject As Long) As Long
 函数 功能
CreatePen 根据提供线条类型、宽度、颜色创建一个画笔对象
CreatePenIndirect 根据一个逻辑字体结构创建一个画笔 
ExtCreatePen 建立扩展画笔
SelectObject 把画笔选入设备环境 

我们通过Create一类的创建画笔函数创建完一个画笔后,必须要将其选入设备环境DC中,使用的函数是SelectObject,此时在设备环境上绘制图形,其轮廓才会依据该画笔显示。当画笔使用完成后,我们需要再调用一次SelectObject,将设备环境DC中原有的画笔恢复,最后还需要使用DeleteObject将其删除。

posted @ 2015-09-17 12:04  alexywt  阅读(722)  评论(0编辑  收藏  举报