VB6.0 【GDI+ 画直线】

来源:互联网 发布:淘宝账户可以注销 编辑:程序博客网 时间:2024/04/29 03:25

‘窗口代码Option ExplicitDim 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 '画直线IEnd SubPrivate Sub Form_Unload(Cancel As Integer)    GdipDeletePen m_Pen '删除画笔    GdipDeleteGraphics m_graphics '释放内存    TerminateGDIPlus  'Gdiplus关闭End Sub


'模块代码Option Explicit    Dim m_token As LongPublic Type GdiplusStartupInput    GdiplusVersion As Long    DebugEventCallback As Long    SuppressBackgroundThread As Long    SuppressExternalCodecs As LongEnd TypePublic Enum GpUnit    UnitWorld    UnitDisplay    UnitPixel    UnitPoint    UnitInch    UnitDocument    UnitMillimeterEnd Enum'-----------------------------------------------------------------------------------------------------------------------Public Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, Graphics As Long) As LongPublic Declare Function GdiplusStartup Lib "gdiplus" (token As Long, inputbuf As GdiplusStartupInput, Optional ByVal outputbuf As Long = 0) As LongPublic Declare Function GdiplusShutdown Lib "gdiplus" (ByVal token As Long) As LongPublic Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal Graphics As Long) As LongPublic Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal Color As Long, ByVal Width As Single, ByVal unit As GpUnit, pen As Long) As LongPublic 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 LongPublic Declare Function GdipDeletePen Lib "gdiplus" (ByVal pen As Long) As LongPublic Function InitGDIPlus()     '初始化GDI+。使用GID+之前必须初始化 返回一个标记,用作关闭    Dim StartupInput As GdiplusStartupInput    Dim token As Long    StartupInput.GdiplusVersion = 1 '版本 默认为1    GdiplusStartup token, StartupInput, 0    m_token = tokenEnd FunctionPublic Function TerminateGDIPlus()  'Gdiplus关闭        GdiplusShutdown m_tokenEnd Function'RGB颜色转换成ARGBPublic 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

0 0
原创粉丝点击