VB6.0 【GDI+ 画直线】

‘窗口代码
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

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值