当前位置:   article > 正文

VB6.0 【GDI+ 画直线】_vb6.0 initgdiplus

vb6.0 initgdiplus

  1. ‘窗口代码
  2. Option Explicit
  3. Dim m_graphics As Long '设备场景的句柄
  4. Dim m_Pen As Long '画笔
  5. Private Sub Form_Load()
  6. InitGDIPlus '初始化
  7. GdipCreateFromHDC Me.hDC, m_graphics '创建自DC图形
  8. GdipCreatePen1 ChangeColor(255), 1, UnitPixel, m_Pen '创建画笔
  9. GdipDrawLineI m_graphics, m_Pen, 20, 100, 560, 100 '画直线I
  10. End Sub
  11. Private Sub Form_Unload(Cancel As Integer)
  12. GdipDeletePen m_Pen '删除画笔
  13. GdipDeleteGraphics m_graphics '释放内存
  14. TerminateGDIPlus 'Gdiplus关闭
  15. End Sub


  1. '模块代码
  2. Option Explicit
  3. Dim m_token As Long
  4. Public Type GdiplusStartupInput
  5. GdiplusVersion As Long
  6. DebugEventCallback As Long
  7. SuppressBackgroundThread As Long
  8. SuppressExternalCodecs As Long
  9. End Type
  10. Public Enum GpUnit
  11. UnitWorld
  12. UnitDisplay
  13. UnitPixel
  14. UnitPoint
  15. UnitInch
  16. UnitDocument
  17. UnitMillimeter
  18. End Enum
  19. '-----------------------------------------------------------------------------------------------------------------------
  20. Public Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, Graphics As Long) As Long
  21. Public Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As Long
  22. Public Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As Long
  23. Public Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal Graphics As Long) As Long
  24. Public Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal Color As Long, ByVal Width As Single, ByVal unit As GpUnit, pen As Long) As Long
  25. 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
  26. Public Declare Function GdipDeletePen Lib "gdiplus" (ByVal pen As Long) As Long
  27. Public Function InitGDIPlus() '初始化GDI+。使用GID+之前必须初始化 返回一个标记,用作关闭
  28. Dim StartupInput As GdiplusStartupInput
  29. Dim token As Long
  30. StartupInput.GdiplusVersion = 1 '版本 默认为1
  31. GdiplusStartup token, StartupInput, 0
  32. m_token = token
  33. End Function
  34. Public Function TerminateGDIPlus() 'Gdiplus关闭
  35. GdiplusShutdown m_token
  36. End Function
  37. 'RGB颜色转换成ARGB
  38. Public Function ChangeColor(ByVal Color As Long, Optional ByVal Alpha As Long = &HFF000000) As Long
  39. ChangeColor = Alpha Or ((Color And &HFF0000) \ &H10000) Or (Color And &HFF00&) Or ((Color And &HFF&) * &H10000)
  40. End Function

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/448400
推荐阅读
相关标签
  

闽ICP备14008679号