赞
踩
- ‘窗口代码
- Option Explicit
- Dim m_graphics As Long '设备场景的句柄
- Dim m_Pen As Long '画笔
- Private Sub Form_Load()
- InitGDIPlus '初始化
- GdipCreateFromHDC Me.hDC, m_graphics '创建自DC图形
- GdipCreatePen1 ChangeColor(255), 1, UnitPixel, m_Pen '创建画笔
- GdipDrawLineI m_graphics, m_Pen, 20, 100, 560, 100 '画直线I
- End Sub
-
- Private Sub Form_Unload(Cancel As Integer)
- GdipDeletePen m_Pen '删除画笔
- GdipDeleteGraphics m_graphics '释放内存
- TerminateGDIPlus 'Gdiplus关闭
- End Sub
- '模块代码
- Option Explicit
- Dim m_token As Long
- Public Type GdiplusStartupInput
- GdiplusVersion As Long
- DebugEventCallback As Long
- SuppressBackgroundThread As Long
- SuppressExternalCodecs As Long
- End Type
-
- Public Enum GpUnit
- UnitWorld
- UnitDisplay
- UnitPixel
- UnitPoint
- UnitInch
- UnitDocument
- UnitMillimeter
- End Enum
- '-----------------------------------------------------------------------------------------------------------------------
- Public Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, Graphics As Long) As Long
- Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
- Public Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As Long
- Public Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal Graphics As Long) As Long
- Public Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal Color As Long, ByVal Width As Single, ByVal unit As GpUnit, pen As Long) As Long
- Public Declare Function GdipDrawLineI Lib "gdiplus" (ByVal Graphics As Long, ByVal pen As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long) As Long
- Public Declare Function GdipDeletePen Lib "gdiplus" (ByVal pen As Long) As Long
- Public Function InitGDIPlus() '初始化GDI+。使用GID+之前必须初始化 返回一个标记,用作关闭
- Dim StartupInput As GdiplusStartupInput
- Dim token As Long
- StartupInput.GdiplusVersion = 1 '版本 默认为1
- GdiplusStartup token, StartupInput, 0
- m_token = token
- End Function
-
- Public Function TerminateGDIPlus() 'Gdiplus关闭
- GdiplusShutdown m_token
- End Function
- 'RGB颜色转换成ARGB
- Public Function ChangeColor(ByVal Color As Long, Optional ByVal Alpha As Long = &HFF000000) As Long
- ChangeColor = Alpha Or ((Color And &HFF0000) \ &H10000) Or (Color And &HFF00&) Or ((Color And &HFF&) * &H10000)
- End Function
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。