VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "sGdip"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Const COMPILE_AS_OCX = False

'=================================================================================
'sGdip Class                                      by Pedro Aguirrezabal (Shagratt)
'=================================================================================
' Many functions are based/copied from code by many authors like Dilettante,
' Krivous Anatolii Anatolevich (The trick) , Avery P, Eduardo-, Leandro Ascierto,
' Olaf Schmidt, La Volpe and others.
'
'Note: Not all GDI+ functions are declared!
'
'v1.1b (06/06/20)
' +ScreenDPI
' +32Bit Transparent Window (fixed memory leak)
'v1.1d (16/06/20)
' +Change DrawText param names
' +GetSystemHandCursor, +LoadImageA
' +opt NoWrap for text drawing functions
'v1.1e (30/06/20)
' +Improved Line,Rectangle,ForeColor,DrawWidth
' +SetGlobalQuality: set quality on all graphics/text operations
'  (no more set inside everyop except when needed)
'  On start is set to highest quality
' +Range,+RangeL
'v1.1f (09/08/20)
' +SetGlobalQuality dont change values with -1 as parameter
' +SetGlobalQualityRestore: To reset to previous values
' +GetGlobalQualityGFX +GetGlobalQualityTXT to get the current value
' +Both CreateGraphics methods now have optional parameters to set QualityModes on create.
' +EncFileToBase64 can optionally return string code directly
'v1.2 (14/04/21)
' +Rectangle3D (with system colors)
'v1.3 (31/06/21)
' +Converted for OCX use
' +AppPath to detect the path of the project where ocx is being used (thanks J.Balkenende)
' +Fixed LoadImg from ByteArray (can be used multiple times,no more shared stream)
' +Fixed LoadImg from hImage
' +LoadImg Support almost everything (autodetect base 64,hImage,StdPicture,Icon,
'  Filename with relative and absolute path, streams , URL and bytearrays)
'v1.4 (06/10/22)
' -Removed FontManager (made it separate proyect)
' -Removed support for GDI+ Private Font Collections
' +Added Gradient Blending point on FillRect
' +Added fBrushTypeCircularGradient (move center with EffDisplacementX/Y)
'v1.4b (28/10/22)
' +Omit LoadImg Error message when byteArray is empty
' +Replaced my FontManager with FontMemRes (By Leandro Ascierto)
'v1.5 (01/11/22)
' +DrawImgWithEffect() got new params: bFlipX and bFlipY to flip image
'TODO:


'Untested: MaskFormFromPicture

Option Explicit

'test
'Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetProp Lib "user32.dll" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function GetModuleFileNameW Lib "kernel32" (ByVal hModule As Long, ByVal lpFileName As Long, ByVal nSize As Long) As Long

'Events for OpenURL
Event OpenURLStart(url$)
Event OpenURLDataReceiving(InBytesTotal&)
Event OpenURLFinished(data() As Byte)


Public Enum PenAlignment
    PenAlignmentCenter = 0
    PenAlignmentInset = 1
    PenAlignmentOutset = 2
    PenAlignmentLeft = 3
    PenAlignmentRight = 4
End Enum

Private hFontCollection As Long


Private Const WIN32_NULL As Long = 0

'----- TEST IMG LOAD ---------
Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3

Private Const scUserAgent = "VB6"
Private Const INTERNET_FLAG_RELOAD = &H80000000

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer


'--- for GdipCreateBitmapFromScan0
Private Const PixelFormat32bppARGB          As Long = &H26200A
Private Const PixelFormat32bppPARGB         As Long = &HE200B
'--- for GdipDrawImageXxx
'Private Const UnitPixel                     As Long = 2
'--- DIB Section constants
Private Const DIB_RGB_COLORS                As Long = 0 '  color table in RGBs
'--- for GdipSetInterpolationMode
'Private Const InterpolationModeHighQualityBicubic As Long = 7
'--- for Gdip*WorldTransform
'Private Const MatrixOrderAppend             As Long = 1
'--- for GdipBitmapLockBits
Private Const ImageLockModeRead             As Long = &H1
'--- for GlobalAlloc
Private Const GMEM_DDESHARE                 As Long = &H2000
Private Const GMEM_MOVEABLE                 As Long = &H2
'--- for SetClipboardData
Private Const CF_DIBV5                      As Long = 17
Private Const BI_BITFIELDS                  As Long = 3
Private Type BITMAPINFOHEADER
    biSize              As Long
    biWidth             As Long
    biHeight            As Long
    biPlanes            As Integer
    biBitCount          As Integer
    biCompression       As Long
    biSizeImage         As Long
    biXPelsPerMeter     As Long
    biYPelsPerMeter     As Long
    biClrUsed           As Long
    biClrImportant      As Long
End Type


'Public Type RECTL
'    Left As Long
'    Top As Long
'    Width As Long
'    Height As Long
'End Type



Private Type POINTL
   X As Long
   Y As Long
End Type

Private Type POINTF
   X As Single
   Y As Single
End Type


Private Type IconInfo
    fIcon               As Long
    xHotspot            As Long
    yHotspot            As Long
    hbmMask             As Long
    hbmColor            As Long
End Type

Private Type PICTDESC
    lSize               As Long
    lType               As Long
    hBmp                As Long
    hpal                As Long
End Type

Private Type SAFEARRAY1D
    cDims               As Integer
    fFeatures           As Integer
    cbElements          As Long
    cLocks              As Long
    pvData              As Long
    cElements           As Long
    lLbound             As Long
End Type

Private Type BitmapData
    Width               As Long
    Height              As Long
    stride              As Long
    PixelFormat         As Long
    scan0               As Long
    Reserved            As Long
End Type

Private Type BITMAPV5HEADER
    bV5Size             As Long
    bV5Width            As Long
    bV5Height           As Long
    bV5Planes           As Integer
    bV5BitCount         As Integer
    bV5Compression      As Long
    bV5SizeImage        As Long
    bV5XPelsPerMeter    As Long
    bV5YPelsPerMeter    As Long
    bV5ClrUsed          As Long
    bV5ClrImportant     As Long
    bV5RedMask          As Long
    bV5GreenMask        As Long
    bV5BlueMask         As Long
    bV5AlphaMask        As Long
    bV5CSType           As Long
    bV5EndpointsRedX    As Long
    bV5EndpointsRedY    As Long
    bV5EndpointsRedZ    As Long
    bV5EndpointsGreenX  As Long
    bV5EndpointsGreenY  As Long
    bV5EndpointsGreenZ  As Long
    bV5EndpointsBlueX   As Long
    bV5EndpointsBlueY   As Long
    bV5EndpointsBlueZ   As Long
    bV5GammaRed         As Long
    bV5GammaGreen       As Long
    bV5GammaBlue        As Long
    bV5Intent           As Long
    bV5ProfileData      As Long
    bV5ProfileSize      As Long
    bV5Reserved         As Long
End Type

Private Enum BrushType
   BrushTypeSolidColor = 0
   BrushTypeHatchFill = 1
   BrushTypeTextureFill = 2
   BrushTypePathGradient = 3
   BrushTypeLinearGradient = 4
End Enum

Private Enum DashStyle
   DashStyleSolid          ' 0
   DashStyleDash           ' 1
   DashStyleDot            ' 2
   DashStyleDashDot        ' 3
   DashStyleDashDotDot     ' 4
   DashStyleCustom         ' 5
End Enum

' Dash cap constants
Private Enum DashCap
   DashCapFlat = 0
   DashCapRound = 2
   DashCapTriangle = 3
End Enum

' Line cap constants (only the lowest 8 bits are used).
Private Enum LineCap
   LineCapFlat = 0
   LineCapSquare = 1
   LineCapRound = 2
   LineCapTriangle = 3

   LineCapNoAnchor = &H10         ' corresponds to flat cap
   LineCapSquareAnchor = &H11     ' corresponds to square cap
   LineCapRoundAnchor = &H12      ' corresponds to round cap
   LineCapDiamondAnchor = &H13    ' corresponds to triangle cap
   LineCapArrowAnchor = &H14      ' no correspondence

   LineCapCustom = &HFF           ' custom cap

   LineCapAnchorMask = &HF0        ' mask to check for anchor or not.
End Enum

' Custom Line cap type constants
Private Enum CustomLineCapType
   CustomLineCapTypeDefault = 0
   CustomLineCapTypeAdjustableArrow = 1
End Enum

Private Enum FillMode
   FillModeAlternate        ' 0
   FillModeWinding          ' 1
End Enum

Private Type PathData
   Count                As Long
   points               As Long ' Pointer to POINTF array
   types                As Long ' Pointer to BYTE array
End Type

Private Enum WarpMode
   WarpModePerspective     ' 0
   WarpModeBilinear        ' 1
End Enum

' Alpha Compositing mode constants
Private Enum CompositingMode
   CompositingModeSourceOver    ' 0
   CompositingModeSourceCopy    ' 1
End Enum

' Quality mode constants
Private Enum QualityMode
   QualityModeInvalid = -1
   QualityModeDefault = 0
   QualityModeLow = 1       ' Best performance
   QualityModeHigh = 2      ' Best rendering quality
End Enum

' Alpha Compositing quality constants
Private Enum CompositingQuality
   CompositingQualityInvalid = QualityModeInvalid
   CompositingQualityDefault = QualityModeDefault
   CompositingQualityHighSpeed = QualityModeLow
   CompositingQualityHighQuality = QualityModeHigh
   CompositingQualityGammaCorrected
   CompositingQualityAssumeLinear
End Enum

Private Enum TextRenderingHint
   TextRenderingHintSystemDefault = 0            ' Glyph with system default rendering hint
   TextRenderingHintSingleBitPerPixelGridFit     ' Glyph bitmap with hinting
   TextRenderingHintSingleBitPerPixel            ' Glyph bitmap without hinting
   TextRenderingHintAntiAliasGridFit             ' Glyph anti-alias bitmap with hinting
   TextRenderingHintAntiAlias                    ' Glyph anti-alias bitmap without hinting
   TextRenderingHintClearTypeGridFit              ' Glyph CT bitmap with hinting
End Enum

Public Enum InterpolationMode
   InterpolationModeInvalid = QualityModeInvalid
   InterpolationModeDefault = QualityModeDefault
   InterpolationModeLowQuality = QualityModeLow
   InterpolationModeHighQuality = QualityModeHigh
   InterpolationModeBilinear
   InterpolationModeBicubic
   InterpolationModeNearestNeighbor
   InterpolationModeHighQualityBilinear
   InterpolationModeHighQualityBicubic
End Enum

Private Enum MatrixOrder
   MatrixOrderPrepend = 0
   MatrixOrderAppend = 1
End Enum

Private Enum GpUnit  ' aka Unit
   UnitWorld      ' 0 -- World coordinate (non-physical unit)
   UnitDisplay    ' 1 -- Variable -- for PageTransform only
   UnitPixel      ' 2 -- Each unit is one device pixel.
   UnitPoint      ' 3 -- Each unit is a printer's point, or 1/72 inch.
   UnitInch       ' 4 -- Each unit is 1 inch.
   UnitDocument   ' 5 -- Each unit is 1/300 inch.
   UnitMillimeter ' 6 -- Each unit is 1 millimeter.
End Enum

' Coordinate space identifiers
Private Enum CoordinateSpace
   CoordinateSpaceWorld     ' 0
   CoordinateSpacePage      ' 1
   CoordinateSpaceDevice     ' 2
End Enum

' Region Comine Modes
Public Enum CombineMode
   CombineModeReplace      ' 0
   CombineModeIntersect    ' 1
   CombineModeUnion        ' 2
   CombineModeXor          ' 3
   CombineModeExclude      ' 4
   CombineModeComplement   ' 5 (Exclude From)
End Enum

Private Type CharacterRange
   First                As Long
   Length               As Long
End Type

Private Type BlurParams
    Radius As Single
    ExpandEdge As Long
End Type


Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Const RGN_OR As Long = 2

'Private Declare Function TextOut Lib "gdi32" Alias "TextOutW" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As Long, ByVal nCount As Long) As Long
'Private Declare Function DrawTextApi Lib "user32" Alias "DrawTextA" (ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As rect, ByVal wFormat As Long) As Long
Private Declare Function LoadImageA Lib "user32" (hInst&, FileName$, lType&, ForcedSizeX&, ForcedSizeY&, FuLoad&) As Long
'lType&= IMAGE_BITMAP= 0, IMAGE_ICON=1, IMAGE_CURSOR=2
'FuLoad&= LR_LOADFROMFILE | LR_DEFAULTSIZE = &H10 or &H40

Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function UpdateWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hWnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RectF, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function MulDiv Lib "kernel32" (ByVal nNumber As Long, ByVal nNumerator As Long, ByVal nDenominator As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As DeviceParms) As Long
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function DestroyCursor Lib "user32" (ByVal hCursor As Long) As Long
Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlob&, ByVal fDeleteOnRelease As Long, ppstm As stdole.IUnknown) As Long
Private Declare Function GetHGlobalFromStream Lib "ole32" (ByVal ppstm As Long, hGlobal As Long) As Long
Private Declare Function ArrPtr Lib "msvbvm60" Alias "VarPtr" (Ptr() As Any) As Long

'Private Declare Function TranslateColor Lib "olepro32.dll" Alias "OleTranslateColor" (ByVal clr As OLE_COLOR, ByVal palet As Long, Col As Long) As Long
Private Declare Function OleTranslateColor Lib "oleaut32" (ByVal clr As OLE_COLOR, ByVal palet As Long, Col As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
'Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetIconInfo Lib "user32" (ByVal hIcon As Long, pIconInfo As Any) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As Any, ByVal wUsage As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, lpBitsInfo As BITMAPINFO, ByVal wUsage As Long, lpBits As Long, ByVal Handle As Long, ByVal dw As Long) As Long
'Original: Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, lpBitsInfo As BITMAPINFOHEADER, ByVal wUsage As Long, lpBits As Long, ByVal Handle As Long, ByVal dw As Long) As Long
Private Declare Function AlphaBlend Lib "msimg32" (ByVal hDestDC As Long, ByVal lX As Long, ByVal lY As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal widthSrc As Long, ByVal heightSrc As Long, ByVal blendFunct As Long) As Boolean
Private Declare Function OleCreatePictureIndirect Lib "oleaut32" (lpPictDesc As PICTDESC, riid As Any, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function CreateIconIndirect Lib "user32" (pIconInfo As Any) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Declare Function SHCreateMemStream Lib "shlwapi" Alias "#12" (ByRef pInit As Any, ByVal cbInit As Long) As IUnknown
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal clrColor As Long) As Long
'Private Declare Function FillRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
'--- clipboard support
Private Declare Function OpenClipboard Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function EmptyClipboard Lib "user32" () As Long
Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
'--- clipboard support

'--- gdi+
'Private Declare Function GdiplusStartup Lib "gdiplus" (hToken As Long, pInputBuf As Any, Optional ByVal pOutputBuf As Long = 0) As Long
'Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal hGraphics As Long) As Long
'Private Declare Function GdipDrawImageRectRectI Lib "gdiplus" (ByVal hGraphics As Long, ByVal hImage As Long, ByVal dstx As Long, ByVal dsty As Long, ByVal dstwidth As Long, ByVal dstheight As Long, ByVal srcx As Long, ByVal srcy As Long, ByVal srcwidth As Long, ByVal srcheight As Long, Optional ByVal srcUnit As Long = 2, Optional ByVal hImageAttributes As Long, Optional ByVal pfnCallback As Long, Optional ByVal lCallbackData As Long) As Long
'Private Declare Function GdipDrawImageRectRect Lib "gdiplus" (ByVal hGraphics As Long, ByVal hImage As Long, ByVal dstx As Single, ByVal dsty As Single, ByVal dstwidth As Single, ByVal dstheight As Single, ByVal srcx As Single, ByVal srcy As Single, ByVal srcwidth As Single, ByVal srcheight As Single, Optional ByVal srcUnit As Long = 2, Optional ByVal hImageAttributes As Long, Optional ByVal pfnCallback As Long, Optional ByVal lCallbackData As Long) As Long

'Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, hGraphics As Long) As Long



Private Enum GDIPLUS_FONTSTYLE
    FontStyleRegular = 0
    FontStyleBold = 1
    FontStyleItalic = 2
    FontStyleBoldItalic = 3
    FontStyleUnderline = 4
    FontStyleStrikeout = 8
End Enum

Private Enum FontQuality
    DEFAULT_QUALITY = 0
    DRAFT_QUALITY = 1
    PROOF_QUALITY = 2
    NONANTIALIASED_QUALITY = 3
    ANTIALIASED_QUALITY = 4
    CLEARTYPE_QUALITY = 5
    CLEARTYPE_NATURAL_QUALITY = 6
End Enum

Private Const LF_FACESIZE = 32
Private Const LF_FACESIZEW = 32 * 2

Private Type LOGFONTA
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName As String * LF_FACESIZE
End Type

Private Type LOGFONTW
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName As String * LF_FACESIZEW
End Type


Private Enum DeviceParms
    LOGPIXELSX = 88 'Logical pixels/inch in X.
    LOGPIXELSY = 90 'Logical pixels/inch in Y.
End Enum

Private Enum FlushIntention
    FlushIntentionFlush
    FlushIntentionSync
End Enum

Private Enum GdiplusStatus
    Ok = 0
    GenericError = 1
    InvalidParameter = 2
    OutOfMemory = 3
    ObjectBusy = 4
    InsufficientBuffer = 5
    NotImplemented = 6
    Win32Error = 7
    WrongState = 8
    Aborted = 9
    FileNotFound = 10
    ValueOverflow = 11
    AccessDenied = 12
    UnknownImageFormat = 13
    FontFamilyNotFound = 14
    FontStyleNotFound = 15
    NotTrueTypeFont = 16
    UnsupportedGdiplusVersion = 17
    GdiplusNotInitialized = 18
    PropertyNotFound = 19
    PropertyNotSupported = 20
End Enum

Private Enum PixelOffsetMode
    PixelOffsetModeInvalid = -1
    PixelOffsetModeDefault = 0
    PixelOffsetModeHighSpeed = 1
    PixelOffsetModeHighQuality = 2
    PixelOffsetModeNone = 3
    PixelOffsetModeHalf = 4
End Enum

Private Const SmoothingModeAntiAlias As Long = &H4

Private Enum SmoothingMode
    smInvalid = -1
    smDefault = 0
    smHighSpeed = 1
    smHighQuality = 2
    smNone = 3
    smAntiAlias = 4
End Enum

Public Enum pStringAlignment
    pStringAlignmentnear = 0
    pStringAlignmentCenter = 1
    pStringAlignmentFar = 2
End Enum

Private Enum StringAlignment
    StringAlignmentnear = 0
    StringAlignmentCenter = 1
    StringAlignmentFar = 2
End Enum

'Private Enum unit
'    UnitWorld = 0
'    UnitDisplay = 1
'    UnitPixel = 2
'    UnitPoint = 3
'    UnitInch = 4
'    UnitDocument = 5
'    UnitMillimeter = 6
'End Enum

Private Type GDIPlusStartupInput
    GdiPlusVersion As Long
    DebugEventCallback As Long
    'Boolean value that specifies whether to suppress the GDI+ background
    'thread. If you set this member to TRUE, GdiplusStartup returns (in
    'its output parameter) a pointer to a hook function and a pointer to
    'an unhook function. You must call those functions appropriately to
    'replace the background thread. If you do not want to be responsible
    'for calling the hook and unhook functions, set this member to FALSE:
    SuppressBackgroundThread As Long
    SuppressExternalCodecs As Long
End Type

Private Type CLSID
   Data1                As Long
   Data2                As Integer
   Data3                As Integer
   Data4(0 To 7) As Byte
End Type

Private Enum EncoderParameterValueType
   EncoderParameterValueTypeByte = 1              ' 8-bit unsigned int
   EncoderParameterValueTypeASCII = 2             ' 8-bit byte containing one 7-bit ASCII
   ' code. NULL terminated.
   EncoderParameterValueTypeShort = 3             ' 16-bit unsigned int
   EncoderParameterValueTypeLong = 4              ' 32-bit unsigned int
   EncoderParameterValueTypeRational = 5          ' Two Longs. The first Long is the
   ' numerator the second Long expresses the
   ' denomintor.
   EncoderParameterValueTypeLongRange = 6         ' Two longs which specify a range of
   ' integer values. The first Long specifies
   ' the lower end and the second one
   ' specifies the higher end. All values
   ' are inclusive at both ends
   EncoderParameterValueTypeUndefined = 7         ' 8-bit byte that can take any value
   ' depending on field definition
   EncoderParameterValueTypeRationalRange = 8      ' Two Rationals. The first Rational
   ' specifies the lower end and the second
   ' specifies the higher end. All values
   ' are inclusive at both ends
End Enum

Private Type GUID
    Data1           As Long
    Data2           As Integer
    Data3           As Integer
    Data4(0 To 7)   As Byte
End Type

' Encoder Parameter structure
Private Type EncoderParameter
   GUID                 As GUID                          ' GUID of the parameter
   NumberOfValues       As Long                 ' Number of the parameter values; usually 1
   type                 As EncoderParameterValueType      ' Value type, like ValueTypeLONG  etc.
   value                As Long                          ' A pointer to the parameter values
End Type

' Encoder Parameters structure
Private Type EncoderParameters
   Count                As Long                          ' Number of parameters in this structure; Should be 1
   Parameter(15)        As EncoderParameter          ' Parameter values; this CAN be an array!!!! (Use CopyMemory and a string or byte array as workaround)
End Type

Private Enum ImageType
   ImageTypeUnknown    ' 0
   ImageTypeBitmap     ' 1
   ImageTypeMetafile   ' 2
End Enum

Private Enum RotateFlipType
   RotateNoneFlipNone = 0
   Rotate90FlipNone = 1
   Rotate180FlipNone = 2
   Rotate270FlipNone = 3

   RotateNoneFlipX = 4
   Rotate90FlipX = 5
   Rotate180FlipX = 6
   Rotate270FlipX = 7

   RotateNoneFlipY = Rotate180FlipX
   Rotate90FlipY = Rotate270FlipX
   Rotate180FlipY = RotateNoneFlipX
   Rotate270FlipY = Rotate90FlipX

   RotateNoneFlipXY = Rotate180FlipNone
   Rotate90FlipXY = Rotate270FlipNone
   Rotate180FlipXY = RotateNoneFlipNone
   Rotate270FlipXY = Rotate90FlipNone
End Enum

Private Type ColorPalette
   Flags                As Long           ' Palette flags
   Count                As Long           ' Number of color entries
   Entries              As Long         ' Palette color entries; this CAN be an array!!!! (Use CopyMemory and a string or byte array as workaround)
End Type

Private Type PropertyItem
   propId               As Long              ' ID of this property
   Length               As Long              ' Length of the property value, in bytes
   type                 As Integer             ' Type of the value, as one of TAG_TYPE_XXX
   ' defined above
   value                As Long               ' property value
End Type

' Line join constants
Private Enum LineJoin
    LineJoinMiter = 0
    LineJoinBevel = 1
    LineJoinRound = 2
    LineJoinMiterClipped = 3
End Enum



' Pen's Fill types
Private Enum PenType
   PenTypeSolidColor = BrushTypeSolidColor
   PenTypeHatchFill = BrushTypeHatchFill
   PenTypeTextureFill = BrushTypeTextureFill
   PenTypePathGradient = BrushTypePathGradient
   PenTypeLinearGradient = BrushTypeLinearGradient
   PenTypeUnknown = -1
End Enum


Private Type RGBQUAD
   rgbBlue              As Byte
   rgbGreen             As Byte
   rgbRed               As Byte
   rgbReserved          As Byte
End Type


Private Type BITMAPINFO
   bmiHeader            As BITMAPINFOHEADER
   bmiColors            As RGBQUAD
End Type

'' Various Hatch Styles
'Private Enum HatchStyle
'   HatchStyleHorizontal                   ' 0
'   HatchStyleVertical                     ' 1
'   HatchStyleForwardDiagonal              ' 2
'   HatchStyleBackwardDiagonal             ' 3
'   HatchStyleCross                        ' 4
'   HatchStyleDiagonalCross                ' 5
'   HatchStyle05Percent                    ' 6
'   HatchStyle10Percent                    ' 7
'   HatchStyle20Percent                    ' 8
'   HatchStyle25Percent                    ' 9
'   HatchStyle30Percent                    ' 10
'   HatchStyle40Percent                    ' 11
'   HatchStyle50Percent                    ' 12
'   HatchStyle60Percent                    ' 13
'   HatchStyle70Percent                    ' 14
'   HatchStyle75Percent                    ' 15
'   HatchStyle80Percent                    ' 16
'   HatchStyle90Percent                    ' 17
'   HatchStyleLightDownwardDiagonal        ' 18
'   HatchStyleLightUpwardDiagonal          ' 19
'   HatchStyleDarkDownwardDiagonal         ' 20
'   HatchStyleDarkUpwardDiagonal           ' 21
'   HatchStyleWideDownwardDiagonal         ' 22
'   HatchStyleWideUpwardDiagonal           ' 23
'   HatchStyleLightVertical                ' 24
'   HatchStyleLightHorizontal              ' 25
'   HatchStyleNarrowVertical               ' 26
'   HatchStyleNarrowHorizontal             ' 27
'   HatchStyleDarkVertical                 ' 28
'   HatchStyleDarkHorizontal               ' 29
'   HatchStyleDashedDownwardDiagonal       ' 30
'   HatchStyleDashedUpwardDiagonal         ' 31
'   HatchStyleDashedHorizontal             ' 32
'   HatchStyleDashedVertical               ' 33
'   HatchStyleSmallConfetti                ' 34
'   HatchStyleLargeConfetti                ' 35
'   HatchStyleZigZag                       ' 36
'   HatchStyleWave                         ' 37
'   HatchStyleDiagonalBrick                ' 38
'   HatchStyleHorizontalBrick              ' 39
'   HatchStyleWeave                        ' 40
'   HatchStylePlaid                        ' 41
'   HatchStyleDivot                        ' 42
'   HatchStyleDottedGrid                   ' 43
'   HatchStyleDottedDiamond                ' 44
'   HatchStyleShingle                      ' 45
'   HatchStyleTrellis                      ' 46
'   HatchStyleSphere                       ' 47
'   HatchStyleSmallGrid                    ' 48
'   HatchStyleSmallCheckerBoard            ' 49
'   HatchStyleLargeCheckerBoard            ' 50
'   HatchStyleOutlinedDiamond              ' 51
'   HatchStyleSolidDiamond                 ' 52
'
'   HatchStyleTotal
'   HatchStyleLargeGrid = HatchStyleCross  ' 4
'
'   HatchStyleMin = HatchStyleHorizontal
'   HatchStyleMax = HatchStyleTotal - 1
'End Enum

' Various wrap modes for brushes
Private Enum WrapMode
   WrapModeTile         ' 0
   WrapModeTileFlipX    ' 1
   WrapModeTileFlipY    ' 2
   WrapModeTileFlipXY   ' 3
   WrapModeClamp        ' 4
End Enum

Private Enum LinearGradientMode
   LinearGradientModeHorizontal          ' 0
   LinearGradientModeVertical            ' 1
   LinearGradientModeForwardDiagonal     ' 2
   LinearGradientModeBackwardDiagonal    ' 3
End Enum

Private Enum StringFormatFlags
   StringFormatFlagsDirectionRightToLeft = &H1
   StringFormatFlagsDirectionVertical = &H2
   StringFormatFlagsNoFitBlackBox = &H4
   StringFormatFlagsDisplayFormatControl = &H20
   StringFormatFlagsNoFontFallback = &H400
   StringFormatFlagsMeasureTrailingSpaces = &H800
   StringFormatFlagsNoWrap = &H1000
   StringFormatFlagsLineLimit = &H2000

   StringFormatFlagsNoClip = &H4000
End Enum

Private Enum StringTrimming
   StringTrimmingNone = 0
   StringTrimmingCharacter = 1
   StringTrimmingWord = 2
   StringTrimmingEllipsisCharacter = 3
   StringTrimmingEllipsisWord = 4
   StringTrimmingEllipsisPath = 5
End Enum

' National language digit substitution
Private Enum StringDigitSubstitute
   StringDigitSubstituteUser = 0         ' As NLS setting
   StringDigitSubstituteNone = 1
   StringDigitSubstituteNational = 2
   StringDigitSubstituteTraditional = 3
End Enum

' Hotkey prefix interpretation
Private Enum HotkeyPrefix
   HotkeyPrefixNone = 0
   HotkeyPrefixShow = 1
   HotkeyPrefixHide = 2
End Enum

'Private Const EncoderParameterValueTypeLong     As Long = 4
'Private Const PixelFormat24bppRGB               As Long = &H21808
'Private Const UnitPixel                         As Long = &H2&
Private Const ImageCodecJPG                     As String = "{557CF401-1A04-11D3-9A73-0000F81EF32E}"
Private Const ImageCodecPNG                     As String = "{557CF406-1A04-11D3-9A73-0000F81EF32E}"
Private Const EncoderQuality                    As String = "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"

Private Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long

Private Declare Function GetObjectType Lib "gdi32.dll" (ByVal hgdiobj As Long) As Long
Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef Ptr() As Any) As Long

Private Declare Function GdiplusStartup Lib "gdiplus" (ByRef GdipToken As Long, ByRef StartupInput As GDIPlusStartupInput, ByVal pStartupOutput As Long) As GdiplusStatus
Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal GdipToken As Long) As GdiplusStatus

Private Declare Function GdipCreatePath Lib "GdiPlus.dll" (ByVal mBrushMode As Long, ByRef mpath As Long) As Long
Private Declare Function GdipCreatePath2I Lib "gdiplus" (points As POINTL, types As Any, ByVal Count As Long, brushmode As FillMode, Path As Long) As GdiplusStatus
Private Declare Function GdipCreatePath2 Lib "gdiplus" (points As POINTF, types As Any, ByVal Count As Long, brushmode As FillMode, Path As Long) As GdiplusStatus
Private Declare Function GdipClonePath Lib "gdiplus" (ByVal Path As Long, clonePath As Long) As Long
Private Declare Function GdipDeletePath Lib "GdiPlus.dll" (ByVal mpath As Long) As Long
Private Declare Function GdipResetPath Lib "gdiplus" (ByVal Path As Long) As Long

Private Declare Function GdipGetPathTypes Lib "gdiplus" (ByVal Path As Long, types As Any, ByVal Count As Long) As Long
Private Declare Function GdipGetPathPoints Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipGetPathPointsI Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipGetPathFillMode Lib "gdiplus" (ByVal Path As Long, ByVal brushmode As FillMode) As Long
Private Declare Function GdipSetPathFillMode Lib "gdiplus" (ByVal Path As Long, ByVal brushmode As FillMode) As Long
Private Declare Function GdipGetPathData Lib "gdiplus" (ByVal Path As Long, pdata As PathData) As Long
Private Declare Function GdipStartPathFigure Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipClosePathFigure Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipClosePathFigures Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipSetPathMarker Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipClearPathMarkers Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipReversePath Lib "gdiplus" (ByVal Path As Long) As Long
Private Declare Function GdipGetPathLastPoint Lib "gdiplus" (ByVal Path As Long, lastPoint As POINTF) As Long
Private Declare Function GdipAddPathLine Lib "gdiplus" (ByVal Path As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal X2 As Single, ByVal Y2 As Single) As Long
Private Declare Function GdipAddPathLine2 Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathArc Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipAddPathBezier Lib "gdiplus" (ByVal Path As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal X2 As Single, ByVal Y2 As Single, ByVal x3 As Single, ByVal y3 As Single, ByVal x4 As Single, ByVal y4 As Single) As Long
Private Declare Function GdipAddPathBeziers Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathCurve Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathCurve2 Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipAddPathCurve3 Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long, ByVal offset As Long, ByVal numberOfSegments As Long, ByVal tension As Single) As Long
Private Declare Function GdipAddPathClosedCurve Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathClosedCurve2 Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipAddPathRectangle Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipAddPathRectangles Lib "gdiplus" (ByVal Path As Long, RECT As RectF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathEllipse Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipAddPathPie Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipAddPathPolygon Lib "gdiplus" (ByVal Path As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipAddPathPath Lib "gdiplus" (ByVal Path As Long, ByVal addingPath As Long, ByVal bConnect As Long) As Long
Private Declare Function GdipAddPathString Lib "gdiplus" (ByVal Path As Long, ByVal str As String, ByVal Length As Long, ByVal family As Long, ByVal style As Long, ByVal emSize As Single, layoutRect As RectF, ByVal StringFormat As Long) As Long
Private Declare Function GdipAddPathStringI Lib "gdiplus" (ByVal Path As Long, ByVal str As String, ByVal Length As Long, ByVal family As Long, ByVal style As Long, ByVal emSize As Single, layoutRect As RECT, ByVal StringFormat As Long) As Long
Private Declare Function GdipAddPathLineI Lib "gdiplus" (ByVal Path As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function GdipAddPathLine2I Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipAddPathArcI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipAddPathBezierI Lib "gdiplus" (ByVal Path As Long, ByVal x1 As Long, ByVal y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal x3 As Long, ByVal y3 As Long, ByVal x4 As Long, ByVal y4 As Long) As Long
Private Declare Function GdipAddPathBeziersI Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipAddPathCurveI Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipAddPathCurve2I Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long, ByVal tension As Long) As Long
Private Declare Function GdipAddPathCurve3I Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long, ByVal offset As Long, ByVal numberOfSegments As Long, ByVal tension As Single) As Long
Private Declare Function GdipAddPathClosedCurveI Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipAddPathClosedCurve2I Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipAddPathRectangleI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipAddPathRectanglesI Lib "gdiplus" (ByVal Path As Long, rects As RECT, ByVal Count As Long) As Long
Private Declare Function GdipAddPathEllipseI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipAddPathPieI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipAddPathPolygonI Lib "gdiplus" (ByVal Path As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipFlattenPath Lib "gdiplus" (ByVal Path As Long, ByVal matrix As Long, ByVal flatness As Single) As Long
Private Declare Function GdipWindingModeOutline Lib "gdiplus" (ByVal Path As Long, ByVal matrix As Long, ByVal flatness As Single) As Long
Private Declare Function GdipWidenPath Lib "gdiplus" (ByVal nativePath As Long, ByVal pen As Long, ByVal matrix As Long, ByVal flatness As Single) As Long
Private Declare Function GdipWarpPath Lib "gdiplus" (ByVal Path As Long, ByVal matrix As Long, points As POINTF, ByVal Count As Long, ByVal srcx As Single, ByVal srcy As Single, ByVal srcwidth As Single, ByVal srcheight As Single, ByVal WarpMd As WarpMode, ByVal flatness As Single) As Long
Private Declare Function GdipTransformPath Lib "gdiplus" (ByVal Path As Long, ByVal matrix As Long) As Long
Private Declare Function GdipGetPathWorldBounds Lib "gdiplus" (ByVal Path As Long, bounds As RectF, ByVal matrix As Long, ByVal pen As Long) As Long
Private Declare Function GdipGetPathWorldBoundsI Lib "gdiplus" (ByVal Path As Long, bounds As RECT, ByVal matrix As Long, ByVal pen As Long) As Long
Private Declare Function GdipIsVisiblePathPoint Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal graphics As Long, result As Long) As Long
Private Declare Function GdipIsVisiblePathPointI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal graphics As Long, result As Long) As Long
Private Declare Function GdipIsOutlineVisiblePathPoint Lib "gdiplus" (ByVal Path As Long, ByVal X As Single, ByVal Y As Single, ByVal pen As Long, ByVal graphics As Long, result As Long) As Long
Private Declare Function GdipIsOutlineVisiblePathPointI Lib "gdiplus" (ByVal Path As Long, ByVal X As Long, ByVal Y As Long, ByVal pen As Long, ByVal graphics As Long, result As Long) As Long

' PathIterator Functions (ALL)
Private Declare Function GdipCreatePathIter Lib "gdiplus" (iterator As Long, ByVal Path As Long) As Long
Private Declare Function GdipDeletePathIter Lib "gdiplus" (ByVal iterator As Long) As Long
Private Declare Function GdipPathIterNextSubpath Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, startIndex As Long, endIndex As Long, isClosed As Long) As Long
Private Declare Function GdipPathIterNextSubpathPath Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, ByVal Path As Long, isClosed As Long) As Long
Private Declare Function GdipPathIterNextPathType Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, pathType As Any, startIndex As Long, endIndex As Long) As Long
Private Declare Function GdipPathIterNextMarker Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, startIndex As Long, endIndex As Long) As Long
Private Declare Function GdipPathIterNextMarkerPath Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, ByVal Path As Long) As Long
Private Declare Function GdipPathIterGetCount Lib "gdiplus" (ByVal iterator As Long, Count As Long) As Long
Private Declare Function GdipPathIterGetSubpathCount Lib "gdiplus" (ByVal iterator As Long, Count As Long) As Long
Private Declare Function GdipPathIterIsValid Lib "gdiplus" (ByVal iterator As Long, valid As Long) As Long
Private Declare Function GdipPathIterHasCurve Lib "gdiplus" (ByVal iterator As Long, hasCurve As Long) As Long
Private Declare Function GdipPathIterRewind Lib "gdiplus" (ByVal iterator As Long) As Long
' NOTE: The types parameter is treated as a byte array
Private Declare Function GdipPathIterEnumerate Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, points As POINTF, types As Any, ByVal Count As Long) As Long
Private Declare Function GdipPathIterCopyData Lib "gdiplus" (ByVal iterator As Long, resultCount As Long, points As POINTF, types As Any, ByVal startIndex As Long, ByVal endIndex As Long) As Long

' Graphics Functions (No Streaming)
Private Declare Function GdipFlush Lib "gdiplus" (ByVal graphics As Long, ByVal intention As FlushIntention) As Long
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hdc As Long, graphics As Long) As Long
Private Declare Function GdipCreateFromHWND Lib "gdiplus" (ByVal hWnd As Long, graphics As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipGetDC Lib "gdiplus" (ByVal graphics As Long, hdc As Long) As Long
Private Declare Function GdipReleaseDC Lib "gdiplus" (ByVal graphics As Long, ByVal hdc As Long) As Long
Private Declare Function GdipSetCompositingMode Lib "gdiplus" (ByVal graphics As Long, ByVal CompositingMd As CompositingMode) As Long
Private Declare Function GdipGetCompositingMode Lib "gdiplus" (ByVal graphics As Long, CompositingMd As CompositingMode) As Long
Private Declare Function GdipSetRenderingOrigin Lib "gdiplus" (ByVal graphics As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GdipGetRenderingOrigin Lib "gdiplus" (ByVal graphics As Long, X As Long, Y As Long) As Long
Private Declare Function GdipSetCompositingQuality Lib "gdiplus" (ByVal graphics As Long, ByVal CompositingQlty As CompositingQuality) As Long
Private Declare Function GdipGetCompositingQuality Lib "gdiplus" (ByVal graphics As Long, CompositingQlty As CompositingQuality) As Long
Private Declare Function GdipSetSmoothingMode Lib "gdiplus" (ByVal graphics As Long, ByVal SmoothingMd As SmoothingMode) As Long
Private Declare Function GdipGetSmoothingMode Lib "gdiplus" (ByVal graphics As Long, SmoothingMd As SmoothingMode) As Long
Private Declare Function GdipSetPixelOffsetMode Lib "gdiplus" (ByVal graphics As Long, ByVal PixOffsetMode As PixelOffsetMode) As Long
Private Declare Function GdipGetPixelOffsetMode Lib "gdiplus" (ByVal graphics As Long, PixOffsetMode As PixelOffsetMode) As Long
Private Declare Function GdipSetTextRenderingHint Lib "gdiplus" (ByVal graphics As Long, ByVal mode As TextRenderingHint) As Long
Private Declare Function GdipGetTextRenderingHint Lib "gdiplus" (ByVal graphics As Long, mode As TextRenderingHint) As Long
Private Declare Function GdipSetTextContrast Lib "gdiplus" (ByVal graphics As Long, ByVal contrast As Long) As Long
Private Declare Function GdipGetTextContrast Lib "gdiplus" (ByVal graphics As Long, contrast As Long) As Long
Private Declare Function GdipSetInterpolationMode Lib "gdiplus" (ByVal graphics As Long, ByVal interpolation As InterpolationMode) As Long
Private Declare Function GdipGetInterpolationMode Lib "gdiplus" (ByVal graphics As Long, interpolation As InterpolationMode) As Long
Private Declare Function GdipSetWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetWorldTransform Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipMultiplyWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal matrix As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipTranslateWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScaleWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal sx As Single, ByVal sy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotateWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipGetWorldTransform Lib "gdiplus" (ByVal graphics As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetPageTransform Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipGetPageUnit Lib "gdiplus" (ByVal graphics As Long, Unit As GpUnit) As Long
Private Declare Function GdipGetPageScale Lib "gdiplus" (ByVal graphics As Long, sScale As Single) As Long
Private Declare Function GdipSetPageUnit Lib "gdiplus" (ByVal graphics As Long, ByVal Unit As GpUnit) As Long
Private Declare Function GdipSetPageScale Lib "gdiplus" (ByVal graphics As Long, ByVal sScale As Single) As Long
Private Declare Function GdipGetDpiX Lib "gdiplus" (ByVal graphics As Long, dpi As Single) As Long
Private Declare Function GdipGetDpiY Lib "gdiplus" (ByVal graphics As Long, dpi As Single) As Long
Private Declare Function GdipTransformPoints Lib "gdiplus" (ByVal graphics As Long, ByVal destSpace As CoordinateSpace, ByVal srcSpace As CoordinateSpace, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipTransformPointsI Lib "gdiplus" (ByVal graphics As Long, ByVal destSpace As CoordinateSpace, ByVal srcSpace As CoordinateSpace, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipGetNearestColor Lib "gdiplus" (ByVal graphics As Long, argb As Long) As Long
' Creates the Win9x Halftone Palette (even on NT) with correct Desktop colors
Private Declare Function GdipCreateHalftonePalette Lib "gdiplus" () As Long
Private Declare Function GdipDrawLine Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal X2 As Single, ByVal Y2 As Single) As Long
Private 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
Private Declare Function GdipDrawLines Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawLinesI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawArc Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipDrawArcI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipDrawBezier Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal x1 As Single, ByVal y1 As Single, ByVal X2 As Single, ByVal Y2 As Single, ByVal x3 As Single, ByVal y3 As Single, ByVal x4 As Single, ByVal y4 As Single) As Long
Private Declare Function GdipDrawBezierI 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, ByVal x3 As Long, ByVal y3 As Long, ByVal x4 As Long, ByVal y4 As Long) As Long
Private Declare Function GdipDrawBeziers Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawBeziersI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawRectangle Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipDrawRectangleI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipDrawRectangles Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, rects As RectF, ByVal Count As Long) As Long
Private Declare Function GdipDrawRectanglesI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, rects As RECT, ByVal Count As Long) As Long
Private Declare Function GdipDrawEllipse Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipDrawEllipseI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipDrawPie Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipDrawPieI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipDrawPolygon Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawPolygonI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawPath Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal Path As Long) As Long
Private Declare Function GdipDrawCurve Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawCurveI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawCurve2 Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipDrawCurve2I Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipDrawCurve3 Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long, ByVal offset As Long, ByVal numberOfSegments As Long, ByVal tension As Single) As Long
Private Declare Function GdipDrawCurve3I Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long, ByVal offset As Long, ByVal numberOfSegments As Long, ByVal tension As Single) As Long
Private Declare Function GdipDrawClosedCurve Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawClosedCurveI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawClosedCurve2 Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTF, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipDrawClosedCurve2I Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As POINTL, ByVal Count As Long, ByVal tension As Single) As Long
Private Declare Function GdipGraphicsClear Lib "gdiplus" (ByVal graphics As Long, ByVal lColor As Long) As Long
Private Declare Function GdipFillRectangle Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipFillRectangleI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipFillRectangles Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, rects As RectF, ByVal Count As Long) As Long
Private Declare Function GdipFillRectanglesI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, rects As RECT, ByVal Count As Long) As Long
Private Declare Function GdipFillPolygon Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTF, ByVal Count As Long, ByVal FillMd As FillMode) As Long
Private Declare Function GdipFillPolygonI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTL, ByVal Count As Long, ByVal FillMd As FillMode) As Long
Private Declare Function GdipFillPolygon2 Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipFillPolygon2I Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipFillEllipse Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipFillEllipseI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipFillPie Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipFillPieI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
Private Declare Function GdipFillPath Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal Path As Long) As Long
Private Declare Function GdipFillClosedCurve Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipFillClosedCurveI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipFillClosedCurve2 Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTF, ByVal Count As Long, ByVal tension As Single, ByVal FillMd As FillMode) As Long
Private Declare Function GdipFillClosedCurve2I Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As POINTL, ByVal Count As Long, ByVal tension As Single, ByVal FillMd As FillMode) As Long
Private Declare Function GdipFillRegion Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal region As Long) As Long
Private Declare Function GdipDrawImage Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Single, ByVal Y As Single) As Long
Private Declare Function GdipDrawImageI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GdipDrawImageRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single) As Long
Private Declare Function GdipDrawImageRectI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long) As Long
Private Declare Function GdipDrawImagePoints Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, dstpoints As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipDrawImagePointsI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, dstpoints As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipDrawImagePointRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Single, _
   ByVal Y As Single, ByVal srcx As Single, ByVal srcy As Single, ByVal srcwidth As Single, ByVal srcheight As Single, ByVal srcUnit As GpUnit) As Long
Private Declare Function GdipDrawImagePointRectI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal X As Long, _
   ByVal Y As Long, ByVal srcx As Long, ByVal srcy As Long, ByVal srcwidth As Long, ByVal srcheight As Long, ByVal srcUnit As GpUnit) As Long
Private Declare Function GdipDrawImageRectRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal dstx As Single, _
   ByVal dsty As Single, ByVal dstwidth As Long, ByVal dstheight As Single, _
   ByVal srcx As Single, ByVal srcy As Single, ByVal srcwidth As Single, ByVal srcheight As Single, _
   Optional ByVal srcUnit As Long = 2, Optional ByVal hImageAttributes As Long, Optional ByVal pfnCallback As Long, Optional ByVal lCallbackData As Long) As Long
' Callback declaration: Private Function DrawImageAbort(ByVal lpData as Long) as Long
Private Declare Function GdipDrawImageRectRectI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByVal dstx As Long, _
   ByVal dsty As Long, ByVal dstwidth As Long, ByVal dstheight As Long, _
   ByVal srcx As Long, ByVal srcy As Long, ByVal srcwidth As Long, ByVal srcheight As Long, _
   ByVal srcUnit As GpUnit, Optional ByVal imageAttributes As Long = 0, _
   Optional ByVal callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Private Declare Function GdipDrawImagePointsRect Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, _
   points As POINTF, ByVal Count As Long, _
   ByVal srcx As Single, ByVal srcy As Single, ByVal srcwidth As Single, ByVal srcheight As Single, _
   ByVal srcUnit As GpUnit, Optional ByVal imageAttributes As Long = 0, _
   Optional ByVal callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Private Declare Function GdipDrawImagePointsRectI Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, _
   points As POINTL, ByVal Count As Long, _
   ByVal srcx As Long, ByVal srcy As Long, ByVal srcwidth As Long, ByVal srcheight As Long, _
   ByVal srcUnit As GpUnit, Optional ByVal imageAttributes As Long = 0, _
   Optional ByVal callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Private Declare Function GdipEnumerateMetafileDestPoint Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoint As POINTF, lpEnumerateMetafileProc As Long, ByVal callbackData As Long, imageAttributes As Long) As Long
' Callback declaration: Private Function EnumMetafilesProc(Byval rtype as EmfPlusRecordType, byval _ as Long, byval _ as Long, bytes as Any, byval callbackData as long) as long
Private Declare Function GdipEnumerateMetafileDestPointI Lib "gdiplus" (graphics As Long, ByVal metafile As Long, destPoint As POINTL, ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileDestRect Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destRect As RectF, lpEnumerateMetafileProc As Long, ByVal callbackData As Long, imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileDestRectI Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destRect As RECT, lpEnumerateMetafileProc As Long, ByVal callbackData As Long, imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileDestPoints Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoint As POINTF, ByVal Count As Long, lpEnumerateMetafileProc As Long, ByVal callbackData As Long, imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileDestPointsI Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoint As POINTL, ByVal Count As Long, lpEnumerateMetafileProc As Long, ByVal callbackData As Long, imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestPoint Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoint As POINTF, srcRect As RectF, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestPointI Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoint As POINTL, srcRect As RECT, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestRect Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destRect As RectF, srcRect As RectF, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestRectI Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destRect As RECT, srcRect As RECT, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestPoints Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoints As POINTF, ByVal Count As Long, srcRect As RectF, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
Private Declare Function GdipEnumerateMetafileSrcRectDestPointsI Lib "gdiplus" (ByVal graphics As Long, ByVal metafile As Long, destPoints As POINTL, ByVal Count As Long, srcRect As RECT, ByVal srcUnit As GpUnit, _
   ByVal lpEnumerateMetafileProc As Long, ByVal callbackData As Long, ByVal imageAttributes As Long) As Long
' TODO: Declare the EmfPlusRecordType enum and uncomment
'Private Declare Function GdipPlayMetafileRecord Lib "gdiplus" (ByVal metafile As Long, ByVal recordType As EmfPlusRecordType, ByVal flags As Long, ByVal dataSize As Long, byteData As Any) As long
Private Declare Function GdipSetClipGraphics Lib "gdiplus" (ByVal graphics As Long, ByVal srcgraphics As Long, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipSetClipRect Lib "gdiplus" (ByVal graphics As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipSetClipRectI Lib "gdiplus" (ByVal graphics As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipSetClipPath Lib "gdiplus" (ByVal graphics As Long, ByVal Path As Long, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipSetClipRegion Lib "gdiplus" (ByVal graphics As Long, ByVal region As Long, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipSetClipHrgn Lib "gdiplus" (ByVal graphics As Long, ByVal hRgn As Long, ByVal CombineMd As CombineMode) As Long
Private Declare Function GdipResetClip Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipTranslateClip Lib "gdiplus" (ByVal graphics As Long, ByVal dx As Single, ByVal dy As Single) As Long
Private Declare Function GdipTranslateClipI Lib "gdiplus" (ByVal graphics As Long, ByVal dx As Long, ByVal dy As Long) As Long
Private Declare Function GdipGetClip Lib "gdiplus" (ByVal graphics As Long, ByVal region As Long) As Long
Private Declare Function GdipGetClipBounds Lib "gdiplus" (ByVal graphics As Long, RECT As RectF) As Long
Private Declare Function GdipGetClipBoundsI Lib "gdiplus" (ByVal graphics As Long, RECT As RECT) As Long
Private Declare Function GdipIsClipEmpty Lib "gdiplus" (ByVal graphics As Long, result As Long) As Long
Private Declare Function GdipGetVisibleClipBounds Lib "gdiplus" (ByVal graphics As Long, RECT As RectF) As Long
Private Declare Function GdipGetVisibleClipBoundsI Lib "gdiplus" (ByVal graphics As Long, RECT As RECT) As Long
Private Declare Function GdipIsVisibleClipEmpty Lib "gdiplus" (ByVal graphics As Long, result As Long) As Long
Private Declare Function GdipIsVisiblePoint Lib "gdiplus" (ByVal graphics As Long, ByVal X As Single, ByVal Y As Single, result As Long) As Long
Private Declare Function GdipIsVisiblePointI Lib "gdiplus" (ByVal graphics As Long, ByVal X As Long, ByVal Y As Long, result As Long) As Long
Private Declare Function GdipIsVisibleRect Lib "gdiplus" (ByVal graphics As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, result As Long) As Long
Private Declare Function GdipIsVisibleRectI Lib "gdiplus" (ByVal graphics As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, result As Long) As Long
Private Declare Function GdipSaveGraphics Lib "gdiplus" (ByVal graphics As Long, State As Long) As Long
Private Declare Function GdipRestoreGraphics Lib "gdiplus" (ByVal graphics As Long, ByVal State As Long) As Long
Private Declare Function GdipBeginContainer Lib "gdiplus" (ByVal graphics As Long, dstrect As RectF, srcRect As RectF, ByVal Unit As GpUnit, State As Long) As Long
Private Declare Function GdipBeginContainerI Lib "gdiplus" (ByVal graphics As Long, dstrect As RECT, srcRect As RECT, ByVal Unit As GpUnit, State As Long) As Long
Private Declare Function GdipBeginContainer2 Lib "gdiplus" (ByVal graphics As Long, State As Long) As Long
Private Declare Function GdipEndContainer Lib "gdiplus" (ByVal graphics As Long, ByVal State As Long) As Long
'Private Declare Function GdipGetMetafileHeaderFromWmf Lib "gdiplus" (ByVal hWmf As Long, WmfPlaceableFileHdr As WmfPlaceableFileHeader, header As MetafileHeader) As Long
'Private Declare Function GdipGetMetafileHeaderFromEmf Lib "gdiplus" (ByVal hEmf As Long, header As MetafileHeader) As Long
'Private Declare Function GdipGetMetafileHeaderFromFile Lib "gdiplus" (ByVal Filename As String, header As MetafileHeader) As Long
'Private Declare Function GdipGetMetafileHeaderFromMetafile Lib "gdiplus" (ByVal metafile As Long, header As MetafileHeader) As Long
'Private Declare Function GdipGetHemfFromMetafile Lib "gdiplus" (ByVal metafile As Long, hEmf As Long) As Long
'Private Declare Function GdipCreateMetafileFromWmf Lib "gdiplus" (ByVal hWmf As Long, ByVal bDeleteWmf As Long, WmfPlaceableFileHdr As WmfPlaceableFileHeader, ByVal metafile As Long) As Long
'Private Declare Function GdipCreateMetafileFromEmf Lib "gdiplus" (ByVal hEmf As Long, ByVal bDeleteEmf As Long, metafile As Long) As Long
'Private Declare Function GdipCreateMetafileFromFile Lib "gdiplus" (byvalfile As String, metafile As Long) As Long
'Private Declare Function GdipCreateMetafileFromWmfFile Lib "gdiplus" (ByVal file As String, WmfPlaceableFileHdr As WmfPlaceableFileHeader, metafile As Long) As Long
'Private Declare Function GdipRecordMetafile Lib "gdiplus" (ByVal referenceHdc As Long, etype As EmfType, frameRect As RectF, ByVal frameUnit As MetafileFrameUnit, ByVal description As String, metafile As Long) As Long
'Private Declare Function GdipRecordMetafileI Lib "gdiplus" (ByVal referenceHdc As Long, etype As EmfType, frameRect As rect, ByVal frameUnit As MetafileFrameUnit, ByVal description As String, metafile As Long) As Long
'Private Declare Function GdipRecordMetafileFileName Lib "gdiplus" (ByVal Filename As String, ByVal referenceHdc As Long, etype As EmfType, frameRect As RectF, ByVal frameUnit As MetafileFrameUnit, ByVal description As String, metafile As Long) As Long
'Private Declare Function GdipRecordMetafileFileNameI Lib "gdiplus" (ByVal Filename As String, ByVal referenceHdc As Long, etype As EmfType, frameRect As rect, ByVal frameUnit As MetafileFrameUnit, ByVal description As String, metafile As Long) As Long
'Private Declare Function GdipSetMetafileDownLevelRasterizationLimit Lib "gdiplus" (ByVal metafile As Long, ByVal metafileRasterizationLimitDpi As Long) As Long
'Private Declare Function GdipGetMetafileDownLevelRasterizationLimit Lib "gdiplus" (ByVal metafile As Long, metafileRasterizationLimitDpi As Long) As Long

' Image Functions (No Streaming)
Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal FileName As String, Image As Long) As Long
Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal Image As Long) As Long
' NOTE: The encoderParams parameter expects a EncoderParameters struct or a NULL
Private Declare Function GdipSaveImageToFile Lib "gdiplus" (ByVal Image As Long, ByVal FileName As String, clsidEncoder As CLSID, encoderParams As Any) As Long
Private Declare Function GdipSaveAdd Lib "gdiplus" (ByVal Image As Long, encoderParams As EncoderParameters) As Long
Private Declare Function GdipSaveAddImage Lib "gdiplus" (ByVal Image As Long, ByVal newImage As Long, encoderParams As EncoderParameters) As Long
Private Declare Function GdipGetImageGraphicsContext Lib "gdiplus" (ByVal Image As Long, graphics As Long) As Long
Private Declare Function GdipGetImageBounds Lib "gdiplus" (ByVal Image As Long, srcRect As RectF, srcUnit As GpUnit) As Long
Private Declare Function GdipGetImageDimension Lib "gdiplus" (ByVal Image As Long, Width As Single, Height As Single) As Long
Private Declare Function GdipGetImageType Lib "gdiplus" (ByVal Image As Long, itype As ImageType) As Long
Private Declare Function GdipGetImageWidth Lib "gdiplus" (ByVal Image As Long, Width As Long) As Long
Private Declare Function GdipGetImageHeight Lib "gdiplus" (ByVal Image As Long, Height As Long) As Long
Private Declare Function GdipGetImageHorizontalResolution Lib "gdiplus" (ByVal Image As Long, resolution As Single) As Long
Private Declare Function GdipGetImageVerticalResolution Lib "gdiplus" (ByVal Image As Long, resolution As Single) As Long
Private Declare Function GdipGetImageFlags Lib "gdiplus" (ByVal Image As Long, Flags As Long) As Long
Private Declare Function GdipGetImageRawFormat Lib "gdiplus" (ByVal Image As Long, format As CLSID) As Long
Private Declare Function GdipGetImagePixelFormat Lib "gdiplus" (ByVal Image As Long, PixelFormat As Long) As Long
Private Declare Function GdipGetImageThumbnail Lib "gdiplus" (ByVal Image As Long, ByVal thumbWidth As Long, ByVal thumbHeight As Long, thumbImage As Long, _
   Optional ByVal callback As Long = 0, Optional ByVal callbackData As Long = 0) As Long
Private Declare Function GdipGetEncoderParameterListSize Lib "gdiplus" (ByVal Image As Long, clsidEncoder As CLSID, Size As Long) As Long
Private Declare Function GdipGetEncoderParameterList Lib "gdiplus" (ByVal Image As Long, clsidEncoder As CLSID, ByVal Size As Long, buffer As EncoderParameters) As Long
Private Declare Function GdipImageGetFrameDimensionsCount Lib "gdiplus" (ByVal Image As Long, Count As Long) As Long
Private Declare Function GdipImageGetFrameDimensionsList Lib "gdiplus" (ByVal Image As Long, dimensionIDs As CLSID, ByVal Count As Long) As Long
Private Declare Function GdipImageGetFrameCount Lib "gdiplus" (ByVal Image As Long, dimensionID As CLSID, Count As Long) As Long
Private Declare Function GdipImageSelectActiveFrame Lib "gdiplus" (ByVal Image As Long, dimensionID As CLSID, ByVal frameIndex As Long) As Long
Private Declare Function GdipImageRotateFlip Lib "gdiplus" (ByVal Image As Long, ByVal rfType As RotateFlipType) As Long
Private Declare Function GdipGetImagePalette Lib "gdiplus" (ByVal Image As Long, palette As ColorPalette, ByVal Size As Long) As Long
Private Declare Function GdipSetImagePalette Lib "gdiplus" (ByVal Image As Long, palette As ColorPalette) As Long
Private Declare Function GdipGetImagePaletteSize Lib "gdiplus" (ByVal Image As Long, Size As Long) As Long
Private Declare Function GdipGetPropertyCount Lib "gdiplus" (ByVal Image As Long, numOfProperty As Long) As Long
Private Declare Function GdipGetPropertyIdList Lib "gdiplus" (ByVal Image As Long, ByVal numOfProperty As Long, list As Long) As Long
Private Declare Function GdipGetPropertyItemSize Lib "gdiplus" (ByVal Image As Long, ByVal propId As Long, Size As Long) As Long
Private Declare Function GdipGetPropertyItem Lib "gdiplus" (ByVal Image As Long, ByVal propId As Long, ByVal propSize As Long, buffer As PropertyItem) As Long
Private Declare Function GdipGetPropertySize Lib "gdiplus" (ByVal Image As Long, totalBufferSize As Long, numProperties As Long) As Long
Private Declare Function GdipGetAllPropertyItems Lib "gdiplus" (ByVal Image As Long, ByVal totalBufferSize As Long, ByVal numProperties As Long, allItems As PropertyItem) As Long
Private Declare Function GdipRemovePropertyItem Lib "gdiplus" (ByVal Image As Long, ByVal propId As Long) As Long
Private Declare Function GdipSetPropertyItem Lib "gdiplus" (ByVal Image As Long, item As PropertyItem) As Long
Private Declare Function GdipImageForceValidation Lib "gdiplus" (ByVal Image As Long) As Long

' Pen Functions (ALL)
Private Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal Color As Long, ByVal Width As Single, ByVal Unit As GpUnit, pen As Long) As Long
Private Declare Function GdipCreatePen2 Lib "gdiplus" (ByVal brush As Long, ByVal Width As Single, ByVal Unit As GpUnit, pen As Long) As Long
Private Declare Function GdipClonePen Lib "gdiplus" (ByVal pen As Long, clonepen As Long) As Long
Private Declare Function GdipDeletePen Lib "gdiplus" (ByVal pen As Long) As Long
Private Declare Function GdipSetPenWidth Lib "gdiplus" (ByVal pen As Long, ByVal Width As Single) As Long
Private Declare Function GdipGetPenWidth Lib "gdiplus" (ByVal pen As Long, Width As Single) As Long
Private Declare Function GdipSetPenUnit Lib "gdiplus" (ByVal pen As Long, ByVal Unit As GpUnit) As Long
Private Declare Function GdipGetPenUnit Lib "gdiplus" (ByVal pen As Long, Unit As GpUnit) As Long
Private Declare Function GdipSetPenLineCap Lib "gdiplus" Alias "GdipSetPenLineCap197819" (ByVal pen As Long, ByVal startCap As LineCap, ByVal endCap As LineCap, ByVal dcap As DashCap) As Long
Private Declare Function GdipSetPenStartCap Lib "gdiplus" (ByVal pen As Long, ByVal startCap As LineCap) As Long
Private Declare Function GdipSetPenEndCap Lib "gdiplus" (ByVal pen As Long, ByVal endCap As LineCap) As Long
Private Declare Function GdipSetPenDashCap Lib "gdiplus" Alias "GdipSetPenDashCap197819" (ByVal pen As Long, ByVal dcap As DashCap) As Long
Private Declare Function GdipGetPenStartCap Lib "gdiplus" (ByVal pen As Long, startCap As LineCap) As Long
Private Declare Function GdipGetPenEndCap Lib "gdiplus" (ByVal pen As Long, endCap As LineCap) As Long
Private Declare Function GdipGetPenDashCap Lib "gdiplus" Alias "GdipGetPenDashCap197819" (ByVal pen As Long, dcap As DashCap) As Long
Private Declare Function GdipSetPenLineJoin Lib "gdiplus" (ByVal pen As Long, ByVal LnJoin As LineJoin) As Long
Private Declare Function GdipGetPenLineJoin Lib "gdiplus" (ByVal pen As Long, LnJoin As LineJoin) As Long
Private Declare Function GdipSetPenCustomStartCap Lib "gdiplus" (ByVal pen As Long, ByVal customCap As Long) As Long
Private Declare Function GdipGetPenCustomStartCap Lib "gdiplus" (ByVal pen As Long, customCap As Long) As Long
Private Declare Function GdipSetPenCustomEndCap Lib "gdiplus" (ByVal pen As Long, ByVal customCap As Long) As Long
Private Declare Function GdipGetPenCustomEndCap Lib "gdiplus" (ByVal pen As Long, customCap As Long) As Long
Private Declare Function GdipSetPenMiterLimit Lib "gdiplus" (ByVal pen As Long, ByVal miterLimit As Single) As Long
Private Declare Function GdipGetPenMiterLimit Lib "gdiplus" (ByVal pen As Long, miterLimit As Single) As Long
Private Declare Function GdipSetPenMode Lib "gdiplus" (ByVal pen As Long, ByVal penMode As PenAlignment) As Long
Private Declare Function GdipGetPenMode Lib "gdiplus" (ByVal pen As Long, penMode As PenAlignment) As Long
Private Declare Function GdipSetPenTransform Lib "gdiplus" (ByVal pen As Long, ByVal matrix As Long) As Long
Private Declare Function GdipGetPenTransform Lib "gdiplus" (ByVal pen As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetPenTransform Lib "gdiplus" (ByVal pen As Long) As Long
Private Declare Function GdipMultiplyPenTransform Lib "gdiplus" (ByVal pen As Long, ByVal matrix As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipTranslatePenTransform Lib "gdiplus" (ByVal pen As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScalePenTransform Lib "gdiplus" (ByVal pen As Long, ByVal sx As Single, ByVal sy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotatePenTransform Lib "gdiplus" (ByVal pen As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipSetPenColor Lib "gdiplus" (ByVal pen As Long, ByVal argb As Long) As Long
Private Declare Function GdipGetPenColor Lib "gdiplus" (ByVal pen As Long, argb As Long) As Long
Private Declare Function GdipSetPenBrushFill Lib "gdiplus" (ByVal pen As Long, ByVal brush As Long) As Long
Private Declare Function GdipGetPenBrushFill Lib "gdiplus" (ByVal pen As Long, brush As Long) As Long
Private Declare Function GdipGetPenFillType Lib "gdiplus" (ByVal pen As Long, ptype As PenType) As Long
Private Declare Function GdipGetPenDashStyle Lib "gdiplus" (ByVal pen As Long, dStyle As DashStyle) As Long
Private Declare Function GdipSetPenDashStyle Lib "gdiplus" (ByVal pen As Long, ByVal dStyle As DashStyle) As Long
Private Declare Function GdipGetPenDashOffset Lib "gdiplus" (ByVal pen As Long, offset As Single) As Long
Private Declare Function GdipSetPenDashOffset Lib "gdiplus" (ByVal pen As Long, ByVal offset As Single) As Long
Private Declare Function GdipGetPenDashCount Lib "gdiplus" (ByVal pen As Long, Count As Long) As Long
Private Declare Function GdipSetPenDashArray Lib "gdiplus" (ByVal pen As Long, dash As Single, ByVal Count As Long) As Long
Private Declare Function GdipGetPenDashArray Lib "gdiplus" (ByVal pen As Long, dash As Single, ByVal Count As Long) As Long
Private Declare Function GdipGetPenCompoundCount Lib "gdiplus" (ByVal pen As Long, Count As Long) As Long
Private Declare Function GdipSetPenCompoundArray Lib "gdiplus" (ByVal pen As Long, dash As Single, ByVal Count As Long) As Long
Private Declare Function GdipGetPenCompoundArray Lib "gdiplus" (ByVal pen As Long, dash As Single, ByVal Count As Long) As Long

' CustomLineCap Functions (ALL)
Private Declare Function GdipCreateCustomLineCap Lib "gdiplus" (ByVal fillPath As Long, ByVal strokePath As Long, ByVal baseCap As LineCap, ByVal baseInset As Single, customCap As Long) As Long
Private Declare Function GdipDeleteCustomLineCap Lib "gdiplus" (ByVal customCap As Long) As Long
Private Declare Function GdipCloneCustomLineCap Lib "gdiplus" (ByVal customCap As Long, clonedCap As Long) As Long
Private Declare Function GdipGetCustomLineCapType Lib "gdiplus" (ByVal customCap As Long, capType As CustomLineCapType) As Long
Private Declare Function GdipSetCustomLineCapStrokeCaps Lib "gdiplus" (ByVal customCap As Long, ByVal startCap As LineCap, ByVal endCap As LineCap) As Long
Private Declare Function GdipGetCustomLineCapStrokeCaps Lib "gdiplus" (ByVal customCap As Long, startCap As LineCap, endCap As LineCap) As Long
Private Declare Function GdipSetCustomLineCapStrokeJoin Lib "gdiplus" (ByVal customCap As Long, ByVal LnJoin As LineJoin) As Long
Private Declare Function GdipGetCustomLineCapStrokeJoin Lib "gdiplus" (ByVal customCap As Long, LnJoin As LineJoin) As Long
Private Declare Function GdipSetCustomLineCapBaseCap Lib "gdiplus" (ByVal customCap As Long, ByVal baseCap As LineCap) As Long
Private Declare Function GdipGetCustomLineCapBaseCap Lib "gdiplus" (ByVal customCap As Long, baseCap As LineCap) As Long
Private Declare Function GdipSetCustomLineCapBaseInset Lib "gdiplus" (ByVal customCap As Long, ByVal inset As Single) As Long
Private Declare Function GdipGetCustomLineCapBaseInset Lib "gdiplus" (ByVal customCap As Long, inset As Single) As Long
Private Declare Function GdipSetCustomLineCapWidthScale Lib "gdiplus" (ByVal customCap As Long, ByVal widthScale As Single) As Long
Private Declare Function GdipGetCustomLineCapWidthScale Lib "gdiplus" (ByVal customCap As Long, widthScale As Single) As Long

' AdjustableArrowCap Functions (ALL)
Private Declare Function GdipCreateAdjustableArrowCap Lib "gdiplus" (ByVal Height As Single, ByVal Width As Single, ByVal isFilled As Long, cap As Long) As Long
Private Declare Function GdipSetAdjustableArrowCapHeight Lib "gdiplus" (ByVal cap As Long, ByVal Height As Single) As Long
Private Declare Function GdipGetAdjustableArrowCapHeight Lib "gdiplus" (ByVal cap As Long, Height As Single) As Long
Private Declare Function GdipSetAdjustableArrowCapWidth Lib "gdiplus" (ByVal cap As Long, ByVal Width As Single) As Long
Private Declare Function GdipGetAdjustableArrowCapWidth Lib "gdiplus" (ByVal cap As Long, Width As Single) As Long
Private Declare Function GdipSetAdjustableArrowCapMiddleInset Lib "gdiplus" (ByVal cap As Long, ByVal middleInset As Single) As Long
Private Declare Function GdipGetAdjustableArrowCapMiddleInset Lib "gdiplus" (ByVal cap As Long, middleInset As Single) As Long
Private Declare Function GdipSetAdjustableArrowCapFillState Lib "gdiplus" (ByVal cap As Long, ByVal bFillState As Long) As Long
Private Declare Function GdipGetAdjustableArrowCapFillState Lib "gdiplus" (ByVal cap As Long, bFillState As Long) As Long

' Bitmap Functions (No Streaming)
Private Declare Function GdipCreateBitmapFromFile Lib "gdiplus" (ByVal FileName As Long, bitmap As Long) As Long
' NOTE: The scan0 parameter is treated as a byte array
Private Declare Function GdipCreateBitmapFromScan0 Lib "gdiplus" (ByVal Width As Long, ByVal Height As Long, ByVal stride As Long, ByVal PixelFormat As Long, scan0 As Any, bitmap As Long) As Long
Private Declare Function GdipCreateBitmapFromGraphics Lib "gdiplus" (ByVal Width As Long, ByVal Height As Long, ByVal target As Long, bitmap As Long) As Long
' NOTE: DirectX required for this function
'private Declare Function GdipCreateBitmapFromDirectDrawSurface Lib "gdiplus" (surface As DirectDrawSurface7, bitmap As Long) As long
Private Declare Function GdipCreateBitmapFromGdiDib Lib "gdiplus" (gdiBitmapInfo As BITMAPINFO, ByVal gdiBitmapData As Long, bitmap As Long) As Long
Private Declare Function GdipCreateBitmapFromHBITMAP Lib "gdiplus" (ByVal hbm As Long, ByVal hpal As Long, bitmap As Long) As Long
Private Declare Function GdipCreateHBITMAPFromBitmap Lib "gdiplus" (ByVal bitmap As Long, hbmReturn As Long, ByVal background As Long) As Long
Private Declare Function GdipCreateBitmapFromHICON Lib "gdiplus" (ByVal hIcon As Long, bitmap As Long) As Long
Private Declare Function GdipCreateHICONFromBitmap Lib "gdiplus" (ByVal bitmap As Long, hbmReturn As Long) As Long
Private Declare Function GdipCreateBitmapFromResource Lib "gdiplus" (ByVal hInstance As Long, ByVal lpBitmapName As String, bitmap As Long) As Long
Private Declare Function GdipCloneBitmapArea Lib "gdiplus" (ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, ByVal PixelFormat As Long, ByVal srcBitmap As Long, dstBitmap As Long) As Long
Private Declare Function GdipCloneBitmapAreaI Lib "gdiplus" (ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal PixelFormat As Long, ByVal srcBitmap As Long, dstBitmap As Long) As Long
'//lock bitmap in memory: so it can be (1) read or written to,and (2) CONVERT to a target format, here PixelFormat32bppRGB
'//use target format to be sure how many bytes you have (to read) per pixel, original bitmap may be only RGB
'//where you have only 3 bytes per pixel or some other format
'//LockBits fills the given 'bitmapData' structure...
Private Declare Function GdipBitmapLockBits Lib "gdiplus" (ByVal bitmap As Long, RECT As RECT, ByVal Flags As Long, ByVal PixelFormat As Long, lockedBitmapData As BitmapData) As Long
Private Declare Function GdipBitmapUnlockBits Lib "gdiplus" (ByVal bitmap As Long, lockedBitmapData As BitmapData) As Long
Private Declare Function GdipBitmapGetPixel Lib "gdiplus" (ByVal bitmap As Long, ByVal X As Long, ByVal Y As Long, Color As Long) As Long
Private Declare Function GdipBitmapSetPixel Lib "gdiplus" (ByVal bitmap As Long, ByVal X As Long, ByVal Y As Long, ByVal Color As Long) As Long
Private Declare Function GdipBitmapSetResolution Lib "gdiplus" (ByVal bitmap As Long, ByVal xdpi As Single, ByVal ydpi As Single) As Long

' CachedBitmap Functions (ALL)
Private Declare Function GdipCreateCachedBitmap Lib "gdiplus" (ByVal bitmap As Long, ByVal graphics As Long, cachedBitmap As Long) As Long
Private Declare Function GdipDeleteCachedBitmap Lib "gdiplus" (ByVal cachedBitmap As Long) As Long
Private Declare Function GdipDrawCachedBitmap Lib "gdiplus" (ByVal graphics As Long, ByVal cachedBitmap As Long, ByVal X As Long, ByVal Y As Long) As Long

' Brush Functions (ALL)
Private Declare Function GdipCloneBrush Lib "gdiplus" (ByVal brush As Long, cloneBrush As Long) As Long
Private Declare Function GdipDeleteBrush Lib "gdiplus" (ByVal brush As Long) As Long
Private Declare Function GdipGetBrushType Lib "gdiplus" (ByVal brush As Long, brshType As BrushType) As Long

' HatchBrush Functions (ALL)
Private Declare Function GdipCreateHatchBrush Lib "gdiplus" (ByVal style As HatchStyle, ByVal forecolr As Long, ByVal backcolr As Long, brush As Long) As Long
Private Declare Function GdipGetHatchStyle Lib "gdiplus" (ByVal brush As Long, style As HatchStyle) As Long
Private Declare Function GdipGetHatchForegroundColor Lib "gdiplus" (ByVal brush As Long, forecolr As Long) As Long
Private Declare Function GdipGetHatchBackgroundColor Lib "gdiplus" (ByVal brush As Long, backcolr As Long) As Long

' SolidBrush Functions (ALL)
Private Declare Function GdipCreateSolidFill Lib "gdiplus" (ByVal argb As Long, brush As Long) As Long
Private Declare Function GdipSetSolidFillColor Lib "gdiplus" (ByVal brush As Long, ByVal argb As Long) As Long
Private Declare Function GdipGetSolidFillColor Lib "gdiplus" (ByVal brush As Long, argb As Long) As Long

' LineBrush Functions (ALL)
Private Declare Function GdipCreateLineBrush Lib "gdiplus" (point1 As POINTF, point2 As POINTF, ByVal color1 As Long, ByVal color2 As Long, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipCreateLineBrushI Lib "gdiplus" (point1 As POINTL, point2 As POINTL, ByVal color1 As Long, ByVal color2 As Long, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipCreateLineBrushFromRect Lib "gdiplus" (RECT As RectF, ByVal color1 As Long, ByVal color2 As Long, ByVal mode As LinearGradientMode, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipCreateLineBrushFromRectI Lib "gdiplus" (RECT As RECT, ByVal color1 As Long, ByVal color2 As Long, ByVal mode As LinearGradientMode, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipCreateLineBrushFromRectWithAngle Lib "gdiplus" (RECT As RectF, ByVal color1 As Long, ByVal color2 As Long, ByVal Angle As Single, ByVal isAngleScalable As Long, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipCreateLineBrushFromRectWithAngleI Lib "gdiplus" (RECT As RECT, ByVal color1 As Long, ByVal color2 As Long, ByVal Angle As Single, ByVal isAngleScalable As Long, ByVal WrapMd As WrapMode, lineGradient As Long) As Long
Private Declare Function GdipSetLineColors Lib "gdiplus" (ByVal brush As Long, ByVal color1 As Long, ByVal color2 As Long) As Long
Private Declare Function GdipGetLineColors Lib "gdiplus" (ByVal brush As Long, lColors As Long) As Long
Private Declare Function GdipGetLineRect Lib "gdiplus" (ByVal brush As Long, RECT As RectF) As Long
Private Declare Function GdipGetLineRectI Lib "gdiplus" (ByVal brush As Long, RECT As RECT) As Long
Private Declare Function GdipSetLineGammaCorrection Lib "gdiplus" (ByVal brush As Long, ByVal useGammaCorrection As Long) As Long
Private Declare Function GdipGetLineGammaCorrection Lib "gdiplus" (ByVal brush As Long, useGammaCorrection As Long) As Long
Private Declare Function GdipGetLineBlendCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipGetLineBlend Lib "gdiplus" (ByVal brush As Long, blend As Single, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetLineBlend Lib "gdiplus" (ByVal brush As Long, blend As Single, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipGetLinePresetBlendCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipGetLinePresetBlend Lib "gdiplus" (ByVal brush As Long, blend As Long, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetLinePresetBlend Lib "gdiplus" (ByVal brush As Long, blend As Long, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetLineSigmaBlend Lib "gdiplus" (ByVal brush As Long, ByVal focus As Single, ByVal theScale As Single) As Long
Private Declare Function GdipSetLineLinearBlend Lib "gdiplus" (ByVal brush As Long, ByVal focus As Single, ByVal theScale As Single) As Long
Private Declare Function GdipSetLineWrapMode Lib "gdiplus" (ByVal brush As Long, ByVal WrapMd As WrapMode) As Long
Private Declare Function GdipGetLineWrapMode Lib "gdiplus" (ByVal brush As Long, WrapMd As WrapMode) As Long
Private Declare Function GdipGetLineTransform Lib "gdiplus" (ByVal brush As Long, matrix As Long) As Long
Private Declare Function GdipSetLineTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetLineTransform Lib "gdiplus" (ByVal brush As Long) As Long
Private Declare Function GdipMultiplyLineTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipTranslateLineTransform Lib "gdiplus" (ByVal brush As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScaleLineTransform Lib "gdiplus" (ByVal brush As Long, ByVal sx As Single, ByVal sy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotateLineTransform Lib "gdiplus" (ByVal brush As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long

' TextureBrush Functions (ALL)
Private Declare Function GdipCreateTexture Lib "gdiplus" (ByVal Image As Long, ByVal WrapMd As WrapMode, texture As Long) As Long
Private Declare Function GdipCreateTexture2 Lib "gdiplus" (ByVal Image As Long, ByVal WrapMd As WrapMode, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, texture As Long) As Long
Private Declare Function GdipCreateTexture2I Lib "gdiplus" (ByVal Image As Long, ByVal WrapMd As WrapMode, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, texture As Long) As Long
Private Declare Function GdipCreateTextureIA Lib "gdiplus" (ByVal Image As Long, ByVal imageAttributes As Long, ByVal X As Single, ByVal Y As Single, ByVal Width As Single, ByVal Height As Single, texture As Long) As Long
Private Declare Function GdipCreateTextureIAI Lib "gdiplus" (ByVal Image As Long, ByVal imageAttributes As Long, ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, texture As Long) As Long
Private Declare Function GdipGetTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long) As Long
Private Declare Function GdipSetTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetTextureTransform Lib "gdiplus" (ByVal brush As Long) As Long
Private Declare Function GdipTranslateTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipMultiplyTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScaleTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal sx As Single, ByVal sy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotateTextureTransform Lib "gdiplus" (ByVal brush As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipSetTextureWrapMode Lib "gdiplus" (ByVal brush As Long, ByVal WrapMd As WrapMode) As Long
Private Declare Function GdipGetTextureWrapMode Lib "gdiplus" (ByVal brush As Long, WrapMd As WrapMode) As Long
Private Declare Function GdipGetTextureImage Lib "gdiplus" (ByVal brush As Long, Image As Long) As Long

' PathGradientBrush Functions (ALL)
Private Declare Function GdipCreatePathGradient Lib "gdiplus" (points As POINTF, ByVal Count As Long, ByVal WrapMd As WrapMode, polyGradient As Long) As Long
Private Declare Function GdipCreatePathGradientI Lib "gdiplus" (points As POINTL, ByVal Count As Long, ByVal WrapMd As WrapMode, polyGradient As Long) As Long
Private Declare Function GdipCreatePathGradientFromPath Lib "gdiplus" (ByVal Path As Long, polyGradient As Long) As Long
Private Declare Function GdipGetPathGradientCenterColor Lib "gdiplus" (ByVal brush As Long, lColors As Long) As Long
Private Declare Function GdipSetPathGradientCenterColor Lib "gdiplus" (ByVal brush As Long, ByVal lColors As Long) As Long
Private Declare Function GdipGetPathGradientSurroundColorsWithCount Lib "gdiplus" (ByVal brush As Long, argb As Long, Count As Long) As Long
Private Declare Function GdipSetPathGradientSurroundColorsWithCount Lib "gdiplus" (ByVal brush As Long, argb As Long, Count As Long) As Long
Private Declare Function GdipGetPathGradientPath Lib "gdiplus" (ByVal brush As Long, ByVal Path As Long) As Long
Private Declare Function GdipSetPathGradientPath Lib "gdiplus" (ByVal brush As Long, ByVal Path As Long) As Long
Private Declare Function GdipGetPathGradientCenterPoint Lib "gdiplus" (ByVal brush As Long, points As POINTF) As Long
Private Declare Function GdipGetPathGradientCenterPointI Lib "gdiplus" (ByVal brush As Long, points As POINTL) As Long
Private Declare Function GdipSetPathGradientCenterPoint Lib "gdiplus" (ByVal brush As Long, points As POINTF) As Long
Private Declare Function GdipSetPathGradientCenterPointI Lib "gdiplus" (ByVal brush As Long, points As POINTL) As Long
Private Declare Function GdipGetPathGradientRect Lib "gdiplus" (ByVal brush As Long, RECT As RectF) As Long
Private Declare Function GdipGetPathGradientRectI Lib "gdiplus" (ByVal brush As Long, RECT As RECT) As Long
Private Declare Function GdipGetPathGradientPointCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipGetPathGradientSurroundColorCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipSetPathGradientGammaCorrection Lib "gdiplus" (ByVal brush As Long, ByVal useGammaCorrection As Long) As Long
Private Declare Function GdipGetPathGradientGammaCorrection Lib "gdiplus" (ByVal brush As Long, useGammaCorrection As Long) As Long
Private Declare Function GdipGetPathGradientBlendCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipGetPathGradientBlend Lib "gdiplus" (ByVal brush As Long, blend As Single, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetPathGradientBlend Lib "gdiplus" (ByVal brush As Long, blend As Single, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipGetPathGradientPresetBlendCount Lib "gdiplus" (ByVal brush As Long, Count As Long) As Long
Private Declare Function GdipGetPathGradientPresetBlend Lib "gdiplus" (ByVal brush As Long, blend As Long, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetPathGradientPresetBlend Lib "gdiplus" (ByVal brush As Long, blend As Long, positions As Single, ByVal Count As Long) As Long
Private Declare Function GdipSetPathGradientSigmaBlend Lib "gdiplus" (ByVal brush As Long, ByVal focus As Single, ByVal sScale As Single) As Long
Private Declare Function GdipSetPathGradientLinearBlend Lib "gdiplus" (ByVal brush As Long, ByVal focus As Single, ByVal sScale As Single) As Long
Private Declare Function GdipGetPathGradientWrapMode Lib "gdiplus" (ByVal brush As Long, WrapMd As WrapMode) As Long
Private Declare Function GdipSetPathGradientWrapMode Lib "gdiplus" (ByVal brush As Long, ByVal WrapMd As WrapMode) As Long
Private Declare Function GdipGetPathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long) As Long
Private Declare Function GdipSetPathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long) As Long
Private Declare Function GdipResetPathGradientTransform Lib "gdiplus" (ByVal brush As Long) As Long
Private Declare Function GdipMultiplyPathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal matrix As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipTranslatePathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal dx As Single, ByVal dy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScalePathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal sx As Single, ByVal sy As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotatePathGradientTransform Lib "gdiplus" (ByVal brush As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipGetPathGradientFocusScales Lib "gdiplus" (ByVal brush As Long, xScale As Single, yScale As Single) As Long
Private Declare Function GdipSetPathGradientFocusScales Lib "gdiplus" (ByVal brush As Long, ByVal xScale As Single, ByVal yScale As Single) As Long


' String format Functions (ALL)
Private Declare Function GdipCreateStringFormat Lib "gdiplus" (ByVal formatAttributes As Long, ByVal language As Integer, StringFormat As Long) As Long
Private Declare Function GdipStringFormatGetGenericDefault Lib "gdiplus" (StringFormat As Long) As Long
Private Declare Function GdipStringFormatGetGenericTypographic Lib "gdiplus" (StringFormat As Long) As Long
Private Declare Function GdipDeleteStringFormat Lib "gdiplus" (ByVal StringFormat As Long) As Long
Private Declare Function GdipCloneStringFormat Lib "gdiplus" (ByVal StringFormat As Long, newFormat As Long) As Long
Private Declare Function GdipSetStringFormatFlags Lib "gdiplus" (ByVal StringFormat As Long, ByVal Flags As Long) As Long
Private Declare Function GdipGetStringFormatFlags Lib "gdiplus" (ByVal StringFormat As Long, Flags As Long) As Long
Private Declare Function GdipSetStringFormatAlign Lib "gdiplus" (ByVal StringFormat As Long, ByVal align As StringAlignment) As Long
Private Declare Function GdipGetStringFormatAlign Lib "gdiplus" (ByVal StringFormat As Long, align As StringAlignment) As Long
Private Declare Function GdipSetStringFormatLineAlign Lib "gdiplus" (ByVal StringFormat As Long, ByVal align As StringAlignment) As Long
Private Declare Function GdipGetStringFormatLineAlign Lib "gdiplus" (ByVal StringFormat As Long, align As StringAlignment) As Long
Private Declare Function GdipSetStringFormatTrimming Lib "gdiplus" (ByVal StringFormat As Long, ByVal trimming As StringTrimming) As Long
Private Declare Function GdipGetStringFormatTrimming Lib "gdiplus" (ByVal StringFormat As Long, trimming As Long) As Long
Private Declare Function GdipSetStringFormatHotkeyPrefix Lib "gdiplus" (ByVal StringFormat As Long, ByVal hkPrefix As HotkeyPrefix) As Long
Private Declare Function GdipGetStringFormatHotkeyPrefix Lib "gdiplus" (ByVal StringFormat As Long, hkPrefix As HotkeyPrefix) As Long
Private Declare Function GdipSetStringFormatTabStops Lib "gdiplus" (ByVal StringFormat As Long, ByVal firstTabOffset As Single, ByVal Count As Long, tabStops As Single) As Long
Private Declare Function GdipGetStringFormatTabStops Lib "gdiplus" (ByVal StringFormat As Long, ByVal Count As Long, firstTabOffset As Single, tabStops As Single) As Long
Private Declare Function GdipGetStringFormatTabStopCount Lib "gdiplus" (ByVal StringFormat As Long, Count As Long) As Long
Private Declare Function GdipSetStringFormatDigitSubstitution Lib "gdiplus" (ByVal StringFormat As Long, ByVal language As Integer, ByVal substitute As StringDigitSubstitute) As Long
Private Declare Function GdipGetStringFormatDigitSubstitution Lib "gdiplus" (ByVal StringFormat As Long, language As Integer, substitute As StringDigitSubstitute) As Long
Private Declare Function GdipGetStringFormatMeasurableCharacterRangeCount Lib "gdiplus" (ByVal StringFormat As Long, Count As Long) As Long
Private Declare Function GdipSetStringFormatMeasurableCharacterRanges Lib "gdiplus" (ByVal StringFormat As Long, ByVal rangeCount As Long, ranges As CharacterRange) As Long

' Matrix Functions (ALL)
Private Declare Function GdipCreateMatrix Lib "gdiplus" (matrix As Long) As Long
Private Declare Function GdipCreateMatrix2 Lib "gdiplus" (ByVal m11 As Single, ByVal m12 As Single, ByVal m21 As Single, ByVal m22 As Single, ByVal dx As Single, ByVal dy As Single, matrix As Long) As Long
Private Declare Function GdipCreateMatrix3 Lib "gdiplus" (RECT As RectF, dstplg As POINTF, matrix As Long) As Long
Private Declare Function GdipCreateMatrix3I Lib "gdiplus" (RECT As RECT, dstplg As POINTL, matrix As Long) As Long
Private Declare Function GdipCloneMatrix Lib "gdiplus" (ByVal matrix As Long, cloneMatrix As Long) As Long
Private Declare Function GdipDeleteMatrix Lib "gdiplus" (ByVal matrix As Long) As Long
Private Declare Function GdipSetMatrixElements Lib "gdiplus" (ByVal matrix As Long, ByVal m11 As Single, ByVal m12 As Single, ByVal m21 As Single, ByVal m22 As Single, ByVal dx As Single, ByVal dy As Single) As Long
Private Declare Function GdipMultiplyMatrix Lib "gdiplus" (ByVal matrix As Long, ByVal matrix2 As Long, ByVal order As MatrixOrder) As Long
Private Declare Function GdipTranslateMatrix Lib "gdiplus" (ByVal matrix As Long, ByVal offsetX As Single, ByVal offsetY As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipScaleMatrix Lib "gdiplus" (ByVal matrix As Long, ByVal scaleX As Single, ByVal scaleY As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipRotateMatrix Lib "gdiplus" (ByVal matrix As Long, ByVal Angle As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipShearMatrix Lib "gdiplus" (ByVal matrix As Long, ByVal shearX As Single, ByVal shearY As Single, ByVal order As MatrixOrder) As Long
Private Declare Function GdipInvertMatrix Lib "gdiplus" (ByVal matrix As Long) As Long
Private Declare Function GdipTransformMatrixPoints Lib "gdiplus" (ByVal matrix As Long, pts As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipTransformMatrixPointsI Lib "gdiplus" (ByVal matrix As Long, pts As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipVectorTransformMatrixPoints Lib "gdiplus" (ByVal matrix As Long, pts As POINTF, ByVal Count As Long) As Long
Private Declare Function GdipVectorTransformMatrixPointsI Lib "gdiplus" (ByVal matrix As Long, pts As POINTL, ByVal Count As Long) As Long
Private Declare Function GdipGetMatrixElements Lib "gdiplus" (ByVal matrix As Long, matrixOut As Single) As Long
Private Declare Function GdipIsMatrixInvertible Lib "gdiplus" (ByVal matrix As Long, result As Long) As Long
Private Declare Function GdipIsMatrixIdentity Lib "gdiplus" (ByVal matrix As Long, result As Long) As Long
Private Declare Function GdipIsMatrixEqual Lib "gdiplus" (ByVal matrix As Long, ByVal matrix2 As Long, result As Long) As Long


'Private Declare Function GdipSetSmoothingMode Lib "GdiPlus.dll" (ByVal mGraphics As Long, ByVal mSmoothingMode As Long) As Long
'Private Declare Function GdipCreateSolidFill Lib "GdiPlus.dll" (ByVal mColor As Long, ByRef mBrush As Long) As Long
'Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As Long
'Private Declare Function GdipFillRectangleI Lib "GdiPlus.dll" (ByVal mGraphics As Long, ByVal mBrush As Long, ByVal mX As Long, ByVal mY As Long, ByVal mWidth As Long, ByVal mHeight As Long) As Long
'Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hDC As Long, ByRef graphics As Long) As Long
'Private Declare Function GdiplusShutdown Lib "gdiplus" (ByVal Token As Long) As Long
'Private Declare Function GdipDeleteBrush Lib "GdiPlus.dll" (ByVal mBrush As Long) As Long
'Private Declare Function GdiplusStartup Lib "gdiplus" (ByRef Token As Long, ByRef lpInput As GdiplusStartupInput, Optional ByRef lpOutput As Any) As Long
'Private Declare Function GdipDeletePen Lib "GdiPlus.dll" (ByVal mPen As Long) As Long
'Private Declare Function GdipDrawArcI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
'Private Declare Function GdipFillPieI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long, ByVal startAngle As Single, ByVal sweepAngle As Single) As Long
'Private 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
'Private Declare Function TranslateColor Lib "olepro32.dll" Alias "OleTranslateColor" (ByVal clr As OLE_COLOR, ByVal palet As Long, Col As Long) As Long
'Private Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal Color As Long, ByVal Width As Single, ByVal unit As Long, pen As Long) As Long
'Private Declare Function GdipDrawPolygonI Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, ByRef pPoints As Any, ByVal count As Long) As Long
'Private Declare Function GdipFillPolygonI Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, ByRef pPoints As Any, ByVal count As Long, ByVal FillMode As Long) As Long
'Private Declare Function GdipDrawEllipseI Lib "GdiPlus.dll" (ByVal mGraphics As Long, ByVal mPen As Long, ByVal mX As Long, ByVal mY As Long, ByVal mWidth As Long, ByVal mHeight As Long) As Long
'Private Declare Function GdipFillEllipseI Lib "GdiPlus.dll" (ByVal mGraphics As Long, ByVal mBrush As Long, ByVal mX As Long, ByVal mY As Long, ByVal mWidth As Long, ByVal mHeight As Long) As Long
'Private Declare Function GdipDrawClosedCurve2I Lib "gdiplus" (ByVal graphics As Long, ByVal pen As Long, points As Any, ByVal count As Long, ByVal tension As Single) As Long
'Private Declare Function GdipFillClosedCurve2I Lib "gdiplus" (ByVal graphics As Long, ByVal brush As Long, points As Any, ByVal count As Long, ByVal tension As Single, ByVal FillMode As Long) As Long
'Private Declare Function GdipDeleteStringFormat Lib "gdiplus" (ByVal gdipFormat As Long) As GdiplusStatus


Private Declare Function GdipCreateImageAttributes Lib "gdiplus" (hImgAttr As Long) As Long
Private Declare Function GdipSetImageAttributesColorMatrix Lib "gdiplus" (ByVal hImgAttr As Long, ByVal lAdjustType As Long, ByVal fAdjustEnabled As Long, clrMatrix As Any, grayMatrix As Any, ByVal lFlags As Long) As Long
Private Declare Function GdipSetImageAttributesColorKeys Lib "gdiplus" (ByVal hImgAttr As Long, ByVal lAdjustType As Long, ByVal fAdjustEnabled As Long, ByVal clrLow As Long, ByVal clrHigh As Long) As Long
Private Declare Function GdipDisposeImageAttributes Lib "gdiplus" (ByVal hImgAttr As Long) As Long
'Private Declare Function GdipCloneBitmapAreaI Lib "gdiplus" (ByVal lX As Long, ByVal lY As Long, ByVal lWidth As Long, ByVal lHeight As Long, ByVal lPixelFormat As Long, ByVal srcBitmap As Long, dstBitmap As Long) As Long
'Private Declare Function GdipCreateBitmapFromHBITMAP Lib "gdiplus" (ByVal hBmp As Long, ByVal hpal As Long, hBtmap As Long) As Long
'Private Declare Function GdipCreateBitmapFromHICON Lib "gdiplus" (ByVal hIcon As Long, hBitmap As Long) As Long
'Private Declare Function GdipGetImageDimension Lib "gdiplus" (ByVal hImage As Long, nWidth As Single, nHeight As Single) As Long   '
'Private Declare Function GdipLoadImageFromFile Lib "gdiplus" (ByVal sFIleName As Long, mImage As Long) As Long
Private Declare Function GdipLoadImageFromStream Lib "gdiplus" (ByVal pStream As Long, ByRef Image As Long) As Long
Private Declare Function GdipSaveImageToStream Lib "gdiplus" (ByVal Image As Long, ByVal Stream As IUnknown, clsidEncoder As GUID, encoderParams As Any) As Long
Private Declare Function GdipCloneImage Lib "gdiplus" (ByVal Image As Long, cloneImage As Long) As Long

'Private Declare Function GdipTranslateWorldTransform Lib "gdiplus" (ByVal hGraphics As Long, ByVal nDx As Single, ByVal nDy As Single, ByVal lOrder As Long) As Long
'Private Declare Function GdipScaleWorldTransform Lib "gdiplus" (ByVal hGraphics As Long, ByVal nSx As Single, ByVal nSy As Single, ByVal lOrder As Long) As Long
'Private Declare Function GdipRotateWorldTransform Lib "gdiplus" (ByVal hGraphics As Long, ByVal nRotation As Single, ByVal lOrder As Long) As Long
'Private Declare Function GdipResetWorldTransform Lib "gdiplus" (ByVal Context As Long) As Long

'Private Declare Function GdipSetInterpolationMode Lib "gdiplus" (ByVal hGraphics As Long, ByVal lMode As Long) As Long
'Private Declare Function GdipBitmapLockBits Lib "gdiplus" (ByVal hBitmap As Long, lpRect As Any, ByVal lFlags As Long, ByVal lPixelFormat As Long, uLockedBitmapData As BitmapData) As Long
'Private Declare Function GdipBitmapUnlockBits Lib "gdiplus" (ByVal hBitmap As Long, uLockedBitmapData As BitmapData) As Long

'Private Declare Function GdipDrawImageRectI Lib "GdiPlus.dll" (ByVal graphics As Long, ByVal Img As Long, ByVal x As Long, ByVal y As Long, ByVal Width As Long, ByVal Height As Long) As Long
'Private Declare Function GdipGetImageWidth Lib "GdiPlus.dll" (ByVal image As Long, Width As Long) As Long
'Private Declare Function GdipGetImageHeight Lib "GdiPlus.dll" (ByVal image As Long, Height As Long) As Long

'Private Declare Function GdipCreateBitmapFromScan0 Lib "gdiplus" (ByVal lWidth As Long, ByVal lHeight As Long, ByVal lStride As Long, ByVal lPixelFormat As Long, ByVal scan0 As Long, hBitmap As Long) As Long
'Private Declare Function GdipDisposeImage Lib "gdiplus" (ByVal hImage As Long) As Long
'Private Declare Function GdipGetImageGraphicsContext Lib "gdiplus" (ByVal hImage As Long, hGraphics As Long) As Long


'Private Declare Function GdipDrawRectangleI Lib "gdiplus" ( _
'    ByVal gdipGraphics As Long, _
'    ByVal gdipPen As Long, _
'    ByVal x As Long, _
'    ByVal y As Long, _
'    ByVal Width As Long, _
'    ByVal Height As Long) As GdiplusStatus

Private Declare Function GdipDrawString Lib "gdiplus" (ByVal gdipGraphics As Long, ByVal pWString As Long, ByVal Length As Long, ByVal gdipFont As Long, ByRef layoutRect As RectF, ByVal gdipStringFormat As Long, ByVal gdipBrush As Long) As GdiplusStatus
Private Declare Function GdipMeasureString Lib "gdiplus" (ByVal gdipGraphics As Long, ByVal pWString As Long, ByVal Length As Long, ByVal gdipFont As Long, ByRef layoutRect As RectF, ByVal gdipStringFormat As Long, ByRef BoundingBox As RectF, ByRef CodepointsFitted As Long, ByRef LinesFilled As Long) As GdiplusStatus
Private Declare Function GdipCreateFontFamilyFromName Lib "gdiplus" (ByVal Name As String, ByVal fontCollection As Long, fontFamily As Long) As Long

'Private Declare Function GdipFlush Lib "gdiplus" ( _
'    ByVal gdipGraphics As Long, _
'    ByVal intention As FlushIntention) As GdiplusStatus

'Private Declare Function GdipGetDpiX Lib "gdiplus" ( _
'    ByVal gdipGraphics As Long, _
'    ByRef DpiX As Single) As GdiplusStatus

'Private Declare Function GdipGetDpiY Lib "gdiplus" ( _
'    ByVal gdipGraphics As Long, _
'    ByRef DpiY As Single) As GdiplusStatus

'Private Declare Function GdipSetPenColor Lib "gdiplus" (ByVal gdipPen As Long, ByVal ARGBColor As Long) As GdiplusStatus
'Private Declare Function GdipSetPenWidth Lib "gdiplus" (ByVal gdipPen As Long, ByVal Width As Single) As GdiplusStatus
'Private Declare Function GdipSetPixelOffsetMode Lib "gdiplus" (ByVal gdipGraphics As Long, ByVal PixelOffsetMode As PixelOffsetMode) As GdiplusStatus
'Private Declare Function GdipSetSolidFillColor Lib "gdiplus" (ByVal gdipSolidBrush As Long, ByVal ARGBColor As Long) As GdiplusStatus
'Private Declare Function GdipSetStringFormatAlign Lib "gdiplus" (ByVal gdipFormat As Long, ByVal StringAlignment As StringAlignment) As GdiplusStatus

'Private Declare Function GdipSetStringFormatLineAlign Lib "gdiplus" ( _
'    ByVal gdipFormat As Long, _
'    ByVal StringAlignment As StringAlignment) As GdiplusStatus

Private Declare Function GdipCreateFontFromLogfontW Lib "gdiplus" (ByVal hdc As Long, ByRef LOGFONTW As LOGFONTW, ByRef pdipFont As Long) As GdiplusStatus
Private Declare Function GdipDeleteFontFamily Lib "gdiplus" (ByVal fontFamily As Long) As Long
Private Declare Function GdipGetFamilyName Lib "gdiplus" (fontFamily As Long, Name As String, lang As Integer) As Long
' Font Functions (ALL)
Private Declare Function GdipCreateFontFromDC Lib "gdiplus" (ByVal hdc As Long, createdfont As Long) As Long
Private Declare Function GdipCreateFontFromLogfontA Lib "gdiplus" (ByVal hdc As Long, LOGFONT As LOGFONTA, createdfont As Long) As Long
Private Declare Function GdipCreateFont Lib "gdiplus" (ByVal fontFamily As Long, ByVal emSize As Single, ByVal style As GDIPLUS_FONTSTYLE, ByVal Unit As Long, createdfont As Long) As Long
Private Declare Function GdipCloneFont Lib "gdiplus" (ByVal curFont As Long, CloneFont As Long) As Long
Private Declare Function GdipDeleteFont Lib "gdiplus" (ByVal curFont As Long) As Long
Private Declare Function GdipGetFamily Lib "gdiplus" (ByVal curFont As Long, family As Long) As Long
Private Declare Function GdipGetFontStyle Lib "gdiplus" (ByVal curFont As Long, style As Long) As Long
Private Declare Function GdipGetFontSize Lib "gdiplus" (ByVal curFont As Long, Size As Single) As Long
Private Declare Function GdipGetFontUnit Lib "gdiplus" (ByVal curFont As Long, Unit As GpUnit) As Long
Private Declare Function GdipGetFontHeight Lib "gdiplus" (ByVal curFont As Long, ByVal graphics As Long, Height As Single) As Long
Private Declare Function GdipGetFontHeightGivenDPI Lib "gdiplus" (ByVal curFont As Long, ByVal dpi As Single, Height As Single) As Long
Private Declare Function GdipGetLogFontA Lib "gdiplus" (ByVal curFont As Long, ByVal graphics As Long, LOGFONT As LOGFONTA) As Long
Private Declare Function GdipGetLogFontW Lib "gdiplus" (ByVal curFont As Long, ByVal graphics As Long, LOGFONT As LOGFONTW) As Long
Private Declare Function GdipNewInstalledFontCollection Lib "gdiplus" (fontCollection As Long) As Long
Private Declare Function GdipNewPrivateFontCollection Lib "gdiplus" (fontCollection As Long) As Long
Private Declare Function GdipDeletePrivateFontCollection Lib "gdiplus" (fontCollection As Long) As Long
Private Declare Function GdipGetFontCollectionFamilyCount Lib "gdiplus" (ByVal fontCollection As Long, numFound As Long) As Long
Private Declare Function GdipGetFontCollectionFamilyList Lib "gdiplus" (ByVal fontCollection As Long, ByVal numSought As Long, gpFamilies As Long, numFound As Long) As Long
Private Declare Function GdipPrivateAddFontFile Lib "gdiplus" (ByVal fontCollection As Long, ByVal FileName As String) As Long
Private Declare Function GdipPrivateAddMemoryFont Lib "gdiplus" (ByVal fontCollection As Long, ByVal memory As Long, ByVal Length As Long) As Long
Private Declare Function CreateFontIndirect Lib "gdi32" Alias "CreateFontIndirectA" (lpLogFont As LOGFONTA) As Long
Private Declare Function CreateFontIndirectW Lib "gdi32" (lpLogFont As LOGFONTW) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long

'test
Private Declare Function CreateFont Lib "gdi32" Alias "CreateFontA" (ByVal h As Long, ByVal w As Long, _
   ByVal E As Long, ByVal O As Long, ByVal w As Long, ByVal i As Long, ByVal u As Long, ByVal s As Long, _
   ByVal C As Long, ByVal OP As Long, ByVal CP As Long, ByVal q As Long, ByVal PAF As Long, ByVal f As String) _
   As Long


'For Blur
Private Declare Function GdipCreateEffect Lib "gdiplus" (ByVal dwCid1 As Long, ByVal dwCid2 As Long, ByVal dwCid3 As Long, ByVal dwCid4 As Long, ByRef Effect As Long) As Long
Private Declare Function GdipSetEffectParameters Lib "gdiplus" (ByVal Effect As Long, ByRef params As Any, ByVal Size As Long) As Long
Private Declare Function GdipDeleteEffect Lib "gdiplus" (ByVal Effect As Long) As Long
Private Declare Function GdipDrawImageFX Lib "gdiplus" (ByVal graphics As Long, ByVal Image As Long, ByRef Source As RectF, ByVal xForm As Long, ByVal Effect As Long, ByVal imageAttributes As Long, ByVal srcUnit As Long) As Long
Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Blur_hDCMemory&, Blur_hBmp&, Blur_OldhBmp&, Blur_UCWidth&, Blur_UCHeight&

'Para WriteValue/ReadValue (Cobein/Leandro Ascierto)
Private Declare Function TlsGetValue Lib "kernel32.dll" (ByVal dwTlsIndex As Long) As Long
Private Declare Function TlsSetValue Lib "kernel32.dll" (ByVal dwTlsIndex As Long, ByVal lpTlsValue As Long) As Long
Private Declare Function TlsFree Lib "kernel32.dll" (ByVal dwTlsIndex As Long) As Long
Private Declare Function TlsAlloc Lib "kernel32.dll" () As Long

'For 32BPP transparent window
Private Type BLENDFUNCTION
    BlendOp As Byte
    BlendFlags As Byte
    SourceConstantAlpha As Byte
    AlphaFormat As Byte
End Type
Private tmp32bppWinSize As POINTL
'Private tempBlend As BLENDFUNCTION
Private tempBI As BITMAPINFO
Private mainBitmap As Long    ' Memory Bitmap
Private oldBitmap As Long
Private blendFunc32bpp As BLENDFUNCTION


Private Const ULW_OPAQUE = &H4
Private Const ULW_COLORKEY = &H1
Private Const ULW_ALPHA = &H2
Private Const BI_RGB As Long = 0&
Private Const AC_SRC_ALPHA As Long = &H1
Private Const AC_SRC_OVER = &H0
Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_EX_LAYERED = &H80000
Private Const WS_EX_COMPOSITED = &H2000000

Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function WindowFromDC Lib "user32" (ByVal hdc As Long) As Long
Private Declare Function UpdateLayeredWindow Lib "user32.dll" (ByVal hWnd As Long, ByVal hdcDst As Long, pptDst As Any, psize As Any, ByVal hdcSrc As Long, pptSrc As Any, ByVal crKey As Long, ByRef pblend As BLENDFUNCTION, ByVal dwFlags As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
'For 32BPP transparent window




Private gdipBrush As Long
Private gdipFont As Long
Private gdipGraphics As Long
Private gdipPen As Long
Private GdipStartupInput As GDIPlusStartupInput
Private gdipStatus As GdiplusStatus
Private GdipToken As Long

Private hdc As Long

Private FillColorARGB As Long
Private ForeColorARGB As Long
Private TwipsPerPixelX As Single
Private TwipsPerPixelY As Single

Private mDrawWidth As Byte
Private mFillColor As stdole.OLE_COLOR
Private mFont As stdole.StdFont
Private mForeColor As stdole.OLE_COLOR

Private mfontMult! 'Font scale cache (for paths)


'Keep Last Value set after changes (for SetGlobalQualityRestore)
Private m_GlobalQualityGFXold As eGdip_GlobalQualityGFX
Private m_GlobalQualityTXTold As eGdip_GlobalQualityTXT
'Keep Current Value set
Private m_GlobalQualityGFX As eGdip_GlobalQualityGFX
Private m_GlobalQualityTXT As eGdip_GlobalQualityTXT


'==============================================
'Font Multiplication to get more precise size
'==============================================
Private Property Get fontMult() As Single
On Error GoTo Err
    If (mfontMult <> 0) Then
        fontMult = mfontMult
    Else
        hdc = GetDC(0&)
        mfontMult = GetDeviceCaps(hdc, LOGPIXELSY) / 72
        ReleaseDC 0&, hdc
        fontMult = mfontMult
    End If
    Exit Property
Err:
    mfontMult = 1.333333333333
    fontMult = mfontMult
End Property

'In pixels:
Public Property Get DrawWidth() As Byte
    DrawWidth = mDrawWidth
End Property
Public Property Let DrawWidth(ByVal PixVal As Byte)
    mDrawWidth = PixVal
    
    If gdipPen = 0 Then
        gdipStatus = GdipCreatePen1(ForeColorARGB, mDrawWidth, UnitPixel, gdipPen)
        If gdipStatus <> Ok Then Err.Raise &H80044300, TypeName(Me), "GdipCreatePen1 error " & CStr(gdipStatus)
    Else
        gdipStatus = GdipSetPenWidth(gdipPen, PixVal)
        If gdipStatus <> 0 Then Err.Raise &H80044100, TypeName(Me), "GdipSetPenWidth error " & CStr(gdipStatus)
    End If
End Property

'FillColor = -1 (i.e. &HFFFFFFFF) means "transparent" here:
Public Property Get FillColor() As stdole.OLE_COLOR
    FillColor = mFillColor
End Property
Public Property Let FillColor(ByVal RHS As stdole.OLE_COLOR)
    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    mFillColor = RHS
    If RHS = -1 Then
        FillColorARGB = RHS
    Else
        If (RHS And &HFF000000) = &H80000000 Then
            RHS = GetSysColor(RHS And &HFFFF&)
        End If
        FillColorARGB = &HFF000000 _
                    Or (RHS And &HFF&) * &H10000 _
                    Or (RHS And &HFF00&) _
                    Or RHS \ &H10000
        If gdipBrush = 0 Then
            gdipStatus = GdipCreateSolidFill(FillColorARGB, gdipBrush)
            If gdipStatus <> Ok Then
                Err.Raise &H80044200, _
                          TypeName(Me), _
                          "GdipCreateSolidFill error " & CStr(gdipStatus)
            End If
        Else
            gdipStatus = GdipSetSolidFillColor(gdipBrush, FillColorARGB)
            If gdipStatus <> Ok Then
                Err.Raise &H80044210, _
                          TypeName(Me), _
                          "GdipSetSolidFillColor error " & CStr(gdipStatus)
            End If
        End If
    End If
End Property

Public Property Get Font() As stdole.StdFont
    Set Font = mFont
End Property
Public Property Set Font(ByVal RHS As stdole.StdFont)
    Set mFont = RHS
End Property
Public Property Let Font(ByVal RHS As stdole.StdFont)
    Set mFont = RHS
End Property



Public Property Get ForeColor() As stdole.OLE_COLOR
    ForeColor = mForeColor
End Property
Public Property Let ForeColor(ByVal RHS As stdole.OLE_COLOR)
    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    mForeColor = RHS
    If (RHS And &HFF000000) = &H80000000 Then
        RHS = GetSysColor(RHS And &HFFFF&)
    End If
    ForeColorARGB = &HFF000000 _
                Or (RHS And &HFF&) * &H10000 _
                Or (RHS And &HFF00&) _
                Or RHS \ &H10000
    If gdipPen = 0 Then
        gdipStatus = GdipCreatePen1(ForeColorARGB, DrawWidth, UnitPixel, gdipPen)
        If gdipStatus <> Ok Then
            Err.Raise &H80044300, _
                      TypeName(Me), _
                      "GdipCreatePen1 error " & CStr(gdipStatus)
        End If
    Else
        gdipStatus = GdipSetPenColor(gdipPen, ForeColorARGB)
        If gdipStatus <> Ok Then
            Err.Raise &H80044310, _
                      TypeName(Me), _
                      "GdipSetPenColor error " & CStr(gdipStatus)
        End If
    End If
End Property


'=======================================
'Force composite mode
'=======================================
Public Sub SetDoubleBuffer(lHwnd&)
    'Force windows composite mode to enable Double buffer (can create more paint calls on some cases)
    Call SetWindowLong(lHwnd, GWL_EXSTYLE, GetWindowLong(lHwnd, GWL_EXSTYLE) Or WS_EX_COMPOSITED)
End Sub

Public Sub CreateGraphics(ByVal hDCCanvas As Long, Optional GFXQuality As eGdip_GlobalQualityGFX = HA_Highest_Aliasing, Optional TXTQuality As eGdip_GlobalQualityTXT = Cleartype)
    gdipStatus = GdipCreateFromHDC(hDCCanvas, gdipGraphics)
    If gdipStatus <> Ok Then Err.Raise &H80044020, TypeName(Me), "GdipCreateFromHDC error " & CStr(gdipStatus)
    SetGlobalQuality GFXQuality, TXTQuality
    hdc = hDCCanvas
    'GetDpiOfGraphics
End Sub


'========================================
'Return the current quality of each mode
'========================================
Public Property Get GetGlobalQualityGFX() As eGdip_GlobalQualityGFX
    GetGlobalQualityGFX = m_GlobalQualityGFX
End Property
Public Property Get GetGlobalQualityTXT() As eGdip_GlobalQualityTXT
    GetGlobalQualityTXT = m_GlobalQualityTXT
End Property

'===========================================
'Set the previous Quality of both modes
'===========================================
'This can be usefull to draw something in a diferent aliasing mode
'and then return back the previous aliasing.
Public Sub SetGlobalQualityRestore()
    SetGlobalQuality m_GlobalQualityGFXold, m_GlobalQualityTXTold
End Sub

'=====================================================
'Set Antialiasing quality on all operations
'=====================================================
'Graphics and Text are set separated
'-1=Dont change what is already set
'0=Lowest-Fastest
'1=Highest Quality
'Rest of values are alternative modes
Public Sub SetGlobalQuality(Optional ByVal GrxLevel As eGdip_GlobalQualityGFX = 1, Optional ByVal TextLevel As eGdip_GlobalQualityTXT = 3)
    RangeL GrxLevel, -1, 5
    RangeL TextLevel, -1, 3
    
    'Save current and old values for SetGlobalQualityRestore
    If (GrxLevel <> -1) Then
        m_GlobalQualityGFXold = m_GlobalQualityGFX
        m_GlobalQualityGFX = GrxLevel
    Else
        m_GlobalQualityGFXold = -1
    End If
    
    If (TextLevel <> -1) Then
        m_GlobalQualityTXTold = m_GlobalQualityTXT
        m_GlobalQualityTXT = TextLevel
    Else
        m_GlobalQualityTXTold = -1
    End If
    
    'Sanity check
    If (gdipGraphics = 0) Then Exit Sub
    
    Select Case GrxLevel
    Case Low_Quality_Fastest 'Low quality, fastest
        GdipSetSmoothingMode gdipGraphics, smNone
        GdipSetCompositingQuality gdipGraphics, CompositingQualityDefault
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeNone
    Case HA_Highest_Aliasing 'Highest Aliasing (DEFAULT)
        GdipSetSmoothingMode gdipGraphics, SmoothingModeAntiAlias
        GdipSetCompositingQuality gdipGraphics, CompositingQualityHighQuality
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeHighQuality
    Case HA_NoOffset 'Like 1 but No offset
        GdipSetSmoothingMode gdipGraphics, SmoothingModeAntiAlias
        GdipSetCompositingQuality gdipGraphics, CompositingQualityGammaCorrected
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeHighQuality
    Case HA_HalfPixelOff ' Better for text
        GdipSetSmoothingMode gdipGraphics, SmoothingModeAntiAlias
        GdipSetCompositingQuality gdipGraphics, CompositingQualityHighSpeed
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeHalf
    Case HA_GammaCorrected 'Like 1 but gamma corrected
        GdipSetSmoothingMode gdipGraphics, SmoothingModeAntiAlias
        GdipSetCompositingQuality gdipGraphics, CompositingQualityGammaCorrected
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeHighQuality
    Case HQ_LinearHalf 'LinearHalf
        GdipSetSmoothingMode gdipGraphics, smHighQuality
        GdipSetCompositingQuality gdipGraphics, CompositingQualityAssumeLinear
        GdipSetPixelOffsetMode gdipGraphics, PixelOffsetModeHalf
    End Select
    
    
    Select Case TextLevel
    Case Low_Quality_TEXT
        GdipSetTextRenderingHint gdipGraphics, TextRenderingHintSingleBitPerPixel
    Case High_Aliasing_TEXT
        GdipSetTextRenderingHint gdipGraphics, TextRenderingHintAntiAlias
    'Case 2 'GridFit
        'GdipSetTextRenderingHint gdipGraphics, TextRenderingHintAntiAliasGridFit
    Case Cleartype, 2
        GdipSetTextRenderingHint gdipGraphics, TextRenderingHintClearTypeGridFit
    End Select
    
End Sub
    
    

Public Sub SetPixelOffsetMode(Optional mode& = 4) ' As PixelOffsetMode)
On Error GoTo Err:
Dim result&

    result& = GdipSetPixelOffsetMode(gdipGraphics, mode)
    If (result& <> 0) Then Debug.Print "pGdipSetPixelOffsetMode Error setting mode: " & mode
    Exit Sub
Err:
    Debug.Print "pGdipSetPixelOffsetMode Err: " & Err.Description
End Sub

Public Sub TranslateDrawings(ByVal x0 As Single, ByVal y0 As Single)
  GdipTranslateWorldTransform gdipGraphics, x0, y0, 0
End Sub

Public Sub ScaleDrawings(ByVal sx As Single, ByVal sy As Single)
  GdipScaleWorldTransform gdipGraphics, sx, sy, 0
End Sub

Public Sub RotateDrawings(ByVal AngleDeg As Single)
    GdipRotateWorldTransform gdipGraphics, AngleDeg, 0
End Sub
Public Sub ResetTransforms()
    GdipResetWorldTransform gdipGraphics
End Sub

Public Sub SetClipRect(X&, Y&, Width&, Height&, mode As CombineMode)
    GdipSetClipRectI gdipGraphics, X, Y, Width, Height, mode
End Sub
Public Sub ResetClip()
    GdipResetClip gdipGraphics
End Sub
    

'TODO: test and enhance
Public Sub Ellipse(X!, Y!, X2!, Y2!)
    Dim RectFScaled As RectF

    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics = 0 Then Err.Raise &H80044010, TypeName(Me), "CreateGraphics() not called"
    With RectFScaled
        .Left = X!
        .Top = Y!
        .Width = X2!
        .Height = Y2!
'        .x = ScaleX(.x)
'        .Y = ScaleY(.Y)
'        .Width = ScaleX(.Width)
'        .Height = ScaleY(.Height)
'        gdipStatus = GdipSetSmoothingMode(gdipGraphics, smAntiAlias)
'        If gdipStatus <> Ok Then
'            err.Raise &H80044500, _
'                      TypeName(Me), _
'                      "GdipSetSmoothingMode error " & CStr(gdipStatus)
'        End If
'        gdipStatus = GdipSetPixelOffsetMode(gdipGraphics, PixelOffsetModeHighQuality)
'        If gdipStatus <> Ok Then
'            err.Raise &H80044510, _
'                      TypeName(Me), _
'                      "GdipSetPixelOffsetMode error " & CStr(gdipStatus)
'        End If
        If FillColor <> -1 Then
            'Fill:
            gdipStatus = GdipFillEllipseI(gdipGraphics, gdipBrush, .Left, .Top, .Width, .Height)
            If gdipStatus <> Ok Then Err.Raise &H80044520, TypeName(Me), "GdipFillEllipseI error " & CStr(gdipStatus)
        End If
        gdipStatus = GdipDrawEllipseI(gdipGraphics, gdipPen, .Left, .Top, .Width, .Height)
        If gdipStatus <> Ok Then Err.Raise &H80044530, TypeName(Me), "GdipDrawEllipseI error " & CStr(gdipStatus)
    End With
End Sub

'EXAMPLE
'        .ForeColor = vbWhite
'        .DrawWidth = 3
'        .Line 1, 1, 150, 150 '(in pixels!)
Public Sub Line(x1&, y1&, X2&, Y2&, Optional nColor& = -1, Optional mOpacity& = 100, Optional lDrawWidth& = -1, Optional ByVal lPenAlignment As PenAlignment = PenAlignmentCenter)
    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics = 0 Then Err.Raise &H80044010, TypeName(Me), "CreateGraphics() not called"
'    x1 = ScaleX(x1)
'    y1 = ScaleY(y1)
'    X2 = ScaleX(X2)
'    Y2 = ScaleY(Y2)

    'Check if global Pen was created, if not, create one
    If gdipPen = 0 Then
        lDrawWidth = 1
        gdipStatus = GdipCreatePen1(ConvertColor(nColor, mOpacity), lDrawWidth, UnitPixel, gdipPen)
    Else
        If (Color& <> -1) Then
            GdipSetPenColor gdipPen, ConvertColor(nColor, mOpacity)
        End If
        If (lDrawWidth <> -1) Then
            GdipSetPenWidth gdipPen, lDrawWidth
        End If
    End If
    If (lPenAlignment <> PenAlignmentCenter) Then GdipSetPenMode gdipPen, lPenAlignment

    gdipStatus = GdipDrawLineI(gdipGraphics, gdipPen, x1, y1, X2, Y2)
    If gdipStatus <> Ok Then
        Err.Raise &H80044620, _
                  TypeName(Me), _
                  "GdipDrawLineI error " & CStr(gdipStatus)
    End If
End Sub

Public Sub Rectangle(X&, Y&, Width&, Height&, Optional ByVal nColor& = -1, Optional ByVal mOpacity& = 100, Optional ByVal Filled As Boolean = False, Optional ByVal lDrawWidth& = -1, Optional ByVal lPenAlignment As PenAlignment = PenAlignmentCenter, Optional UseExistingBrush As Boolean = False)

    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics = 0 Then Err.Raise &H80044010, TypeName(Me), "CreateGraphics() not called"
    
    If (Filled) Then
        If ((gdipBrush <> 0) And Not (UseExistingBrush)) Then
            GdipDeleteBrush gdipBrush
            gdipBrush = 0
        End If
        
        If (gdipBrush = 0) Then
            gdipStatus = GdipCreateSolidFill(ConvertColor(nColor, mOpacity), gdipBrush)
            If gdipStatus <> Ok Then Err.Raise &H80044200, TypeName(Me), "Rectangle GdipCreateSolidFill Err " & CStr(gdipStatus)
        End If
        gdipStatus = GdipFillRectangleI(gdipGraphics, gdipBrush, X, Y, Width, Height)
        If gdipStatus <> Ok Then Err.Raise &H80044720, TypeName(Me), "Rectangle GdipFillRectangleI Err " & CStr(gdipStatus)
        
    Else
        'Only border
        
        'No Border?
        If (lDrawWidth = 0) Then Exit Sub
        
        'Check if global Pen was created, if not, create one
        If gdipPen = 0 Then
            If (lDrawWidth = -1) Then lDrawWidth = 1
            gdipStatus = GdipCreatePen1(ConvertColor(nColor, mOpacity), lDrawWidth, UnitPixel, gdipPen)
        Else
            If (Color& <> -1) Then
                GdipSetPenColor gdipPen, ConvertColor(nColor, mOpacity)
            End If
            If (lDrawWidth <> -1) Then
                GdipSetPenWidth gdipPen, lDrawWidth
            End If
        End If
        If (lPenAlignment <> PenAlignmentCenter) Then GdipSetPenMode gdipPen, lPenAlignment
            
        Dim m!
        GdipGetPenMiterLimit gdipPen, m
        GdipSetPenMiterLimit gdipPen, 60
            
        gdipStatus = GdipDrawRectangleI(gdipGraphics, gdipPen, X, Y, Width, Height)
        If gdipStatus <> Ok Then Err.Raise &H80044730, TypeName(Me), "Rectangle GdipDrawRectangleI Err " & CStr(gdipStatus)
    End If
    
End Sub

'===========================================================
'Dibuja un borde de control con los colores 3D del sistema
'===========================================================
Public Sub Rectangle3D(X&, Y&, Width&, Height&, Optional ByVal Appearance As eGD_Appearance = eGD_Inset, Optional ByVal mOpacity& = 100, Optional ByVal lDrawWidth& = -1, Optional ByVal lPenAlignment As PenAlignment = PenAlignmentCenter)
Dim iAux&
Dim i3DHighL&, i3DLight As Long, i3DShadow&, i3DDKShadow&
    OleTranslateColor vb3DShadow, 0&, i3DShadow&
    OleTranslateColor vb3DDKShadow, 0&, i3DDKShadow&
    OleTranslateColor vb3DLight, 0&, i3DLight
    OleTranslateColor vb3DHighlight, 0&, i3DHighL
    'i3DShadow& = vbRed
    'i3DDKShadow& = vbBlue
    'i3DLight = vbRed
    
    If (Appearance = eGD_Inset) Then
        'Inset
        Call Line(X, Y, X + Width&, Y, i3DShadow&, 100, 1, PenAlignmentInset) ' Top <->
        Call Line(X, Y + 1, X, Y + Height&, i3DShadow&, 100, 1, PenAlignmentInset) ' Left \/ /\
        Call Line(X + 1, Y + 1, X + Width& - 2, Y + 1, i3DDKShadow&, 100, 1, PenAlignmentInset) ' Interior Top-Left <->
        Call Line(X + 1, Y + 1, X + 1, Y + Height& - 1, i3DDKShadow&, 100, 1, PenAlignmentInset) ' Interior Left \/ /\
        If (lDrawWidth& = 1) Then iAux& = 1
        Call Line(X + 1, Y + Height& - 1 + iAux&, X + Width& - 1, Y + Height& - 1 + iAux&, i3DLight, 100, 1, PenAlignmentInset) ' Bottom <->
        Call Line(X + Width& - 1 + iAux&, Y + 1, X + Width& - 1 + iAux&, Y + Height& - 1 + iAux&, i3DLight, 100, 1, PenAlignmentInset) ' left /\ \/
    ElseIf (Appearance = eGD_Raised) Then
        'Raised
        'DEBUG: i3DShadow& = vbRed
        Call Line(X, Y, X + Width&, Y, i3DLight, 100, 1, PenAlignmentInset) ' Top <->
        Call Line(X, Y + 1, X, Y + Height&, i3DLight, 100, 1, PenAlignmentInset) ' Left \/ /\
        Call Line(X + 1, Y + 1, X + Width& - 2, Y + 1, i3DHighL, 100, 1, PenAlignmentInset) ' Interior Top-Left <->
        Call Line(X + 1, Y + 1, X + 1, Y + Height& - 1, i3DHighL, 100, 1, PenAlignmentInset) ' Interior Left \/ /\
        If (lDrawWidth& = 1) Then iAux& = 1
        Call Line(X + 1, Y + Height& - 1 + iAux&, X + Width& - 1, Y + Height& - 1 + iAux&, i3DDKShadow&, 100, 1, PenAlignmentInset) ' Bottom <->
        Call Line(X + Width& - 1 + iAux&, Y + 1, X + Width& - 1 + iAux&, Y + Height& - 1 + iAux&, i3DDKShadow&, 100, 1, PenAlignmentInset) ' left /\ \/
    End If

End Sub


'================================================
'Draw the button caption using drawtext api
'================================================
'Draw Text Converting normal text to unicode and replacing /// to linebreaks
Public Sub DrawText_DRAWSTRINGAPI(sText As String, X!, Y!, XWidth!, YHeight!, ccolor&, Optional Opacity& = 100, _
     Optional HAlign As Long = 0, Optional VAlign As Long = 0, _
     Optional Effect As Long = 0, Optional Rotation! = 0, Optional fFont As StdFont = Nothing, Optional NoWrap As Boolean)
On Error GoTo Err:
    Dim rRect As RectF
    Dim strFontName As String, FontSize As Single, FontStyle&
    Dim FontSizeP As Single 'FontSize for Paths
    Dim bPreservePGraphics As Boolean
    Dim hStatus As Long
    Dim pPath As Long
    Dim pPen As Long
    Dim pBrush As Long
    Dim pFontFamily As Long
    Dim gdipFont As Long
    Dim hFormat As Long
    Dim i&
    Dim pPath2, rRect2 As RectF, auxPsize&, auxEffStart&, offsetX&
    Dim AuxEff&, auxSize&
    Dim HalfW!, HalfH!
    Dim auxt$, auxtP$

    If (sText = "") Then Exit Sub

    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics = 0 Then Err.Raise &H80044010, TypeName(Me), "CreateGraphics() not called"
    
    auxt$ = Replace(sText, "///", vbCrLf)
    auxt$ = Replace(auxt$, "//\/", "///")
    
    'Call GdipSetSmoothingMode(gdipGraphics, 4) '4=SmoothingModeAntiAlias
    'Call GdipSetTextRenderingHint(gdipGraphics, TextRenderingHintAntiAlias)
    
    If (fFont Is Nothing) Then
        If (mFont Is Nothing) Then Set mFont = New StdFont
        Set fFont = mFont
    End If
    
    rRect.Left = X
    rRect.Top = Y
    rRect.Width = XWidth
    rRect.Height = YHeight
    
    hStatus = GdipStringFormatGetGenericDefault(hFormat)
    GdipSetStringFormatAlign hFormat, HAlign
    GdipSetStringFormatLineAlign hFormat, VAlign
    
    If (NoWrap) Then GdipSetStringFormatFlags hFormat, StringFormatFlagsNoWrap
    GdipSetStringFormatTrimming hFormat, StringTrimmingEllipsisCharacter
    GdipSetStringFormatHotkeyPrefix hFormat, HotkeyPrefixShow
    
    'strFontName = "Font Awesome 5 Free Solid"
    strFontName = fFont.Name
    FontSize = fFont.Size
    'for paths
    auxtP$ = StrConv(auxt$, vbUnicode)
    FontSizeP = (FontSize * fontMult) * 1
    
    'FONT REPLACES
    If (strFontName = "MS Sans Serif") Then strFontName = "Microsoft Sans Serif"
    
    'FontStyle
    If (fFont.Bold) Then FontStyle = FontStyleBold
    If (fFont.Italic) Then FontStyle = FontStyle Or FontStyleItalic
    If (fFont.Underline) Then FontStyle = FontStyle Or FontStyleUnderline
    
    If (GdipCreateFontFamilyFromName(StrConv(strFontName, vbUnicode), 0, pFontFamily)) Then
        If (hFontCollection) Then
            If (GdipCreateFontFamilyFromName(StrConv(strFontName, vbUnicode), hFontCollection, pFontFamily)) Then
                GdipCreateFontFamilyFromName StrConv("Microsoft Sans Serif", vbUnicode), 0, pFontFamily
            End If
        Else
            GdipCreateFontFamilyFromName StrConv("Microsoft Sans Serif", vbUnicode), 0, pFontFamily
        End If
    End If
    If (pFontFamily = 0) Then
        Debug.Print "DrawText_DRAWSTRINGAPI Can't create FontFamily: [" & strFontName & "]"
        GoTo CleanUp
    End If
    
    hStatus = GdipCreateFont(pFontFamily, FontSize, FontStyle, GpUnit.UnitPoint, gdipFont)
    If (hStatus <> 0) Then
        Debug.Print "DrawText_DRAWSTRINGAPI Can't create Font: [" & strFontName & "]"
        GoTo CleanUp
    End If
    
    'Text rotation?
    If (Rotation <> 0) Then
        'Calc the area of the text to know where to position the center of the rotation
        Dim BoundRectF As RectF, CodepointsFitted&, LinesFilled&
        GdipMeasureString gdipGraphics&, StrPtr(auxt$), Len(auxt$), gdipFont, rRect, hFormat, BoundRectF, CodepointsFitted, LinesFilled
        
        ''Make centered square area (seems to be not necesary at all)
        'Dim diff!
        'If (BoundRectF.Height > BoundRectF.Width) Then
        '    diff! = (BoundRectF.Height - BoundRectF.Width)
        '    BoundRectF.Width = BoundRectF.Width + diff!
        '    BoundRectF.X = BoundRectF.X - (diff! / 2)
        'ElseIf (BoundRectF.Height < BoundRectF.Width) Then
        '    diff! = (BoundRectF.Width - BoundRectF.Height)
        '    BoundRectF.Height = BoundRectF.Height + diff!
        '    BoundRectF.Y = BoundRectF.Y - (diff! / 2)
        'End If
        
        'Debug area used
        'DrawRoundRect vbCyan, 60, 1, BoundRectF.X, BoundRectF.Y, BoundRectF.Width, BoundRectF.Height, 2
        
        'Rotate and translate
        HalfW = (BoundRectF.Width / 2)
        HalfH = (BoundRectF.Height / 2)
        GdipRotateWorldTransform gdipGraphics, Rotation!, 0
        GdipTranslateWorldTransform gdipGraphics, BoundRectF.Left + HalfW, BoundRectF.Top + HalfH, 1
        
        'Set the new area to draw
        rRect.Left = -HalfW
        rRect.Top = -HalfH
        rRect.Width = BoundRectF.Width
        rRect.Height = BoundRectF.Height

    End If
    
    
   
    If (Effect <> 0) Then
    'Create a path with the string
        hStatus = GdipCreatePath(0, pPath) '0=FillModeAlternate
        GdipAddPathString pPath, auxtP$, -1, pFontFamily, FontStyle&, FontSizeP, rRect, hFormat
   
        'Effects
        '1-5 Black Outline (20%) (size 1-5)
        '6-10 Black Outline (50%)  (size 1-5)
        '11 White Outline (25%) size 2
        '12-15 Same color Outline (25%) (size 1-4)
        '16-21 Black Bottom Shadow (25%-50%) (Size 1-3)
        '22-24 Black Bottom Shadow with border shadow (1-3)
        Select Case Val(Effect)
        Case 1, 2, 3, 4, 5
            GdipCreatePen1 ConvertColor(vbBlack, 20), Effect, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
        Case 6, 7, 8, 9, 10
            GdipCreatePen1 ConvertColor(vbBlack, 50), Effect - 5, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
        Case 11
            GdipCreatePen1 ConvertColor(vbWhite, 25), 2, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
        Case 12, 13, 14, 15
            GdipCreatePen1 ConvertColor(ccolor, 25), Effect - 11, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
        Case 16, 17, 18, 19, 20, 21
            If (Effect > 15 And Effect < 19) Then
                auxEffStart& = 15
                auxPsize& = 1
            Else
                auxEffStart& = 18
                auxPsize& = 2
            End If
            rRect2 = rRect
            rRect2.Top = rRect2.Top + ((Effect - auxEffStart&) / 2) + 0.5
            rRect2.Height = rRect2.Height + ((Effect - auxEffStart&) / 2) + 0.5
            hStatus = GdipCreatePath(0, pPath2) '0=FillModeAlternate
            GdipAddPathString pPath2, auxt$, -1, pFontFamily, FontStyle&, FontSize, rRect2, hFormat
    
            GdipCreateSolidFill ConvertColor(vbBlack, 25 * auxPsize&), pBrush
            hStatus = GdipFillPath(gdipGraphics&, pBrush, pPath2)
    
            GdipDeleteBrush pBrush
            GdipDeletePath (pPath2)
            
        Case 22, 23, 24
            'Solid Shadow and border
            rRect2 = rRect
            rRect2.Top = rRect2.Top + ((Effect - 21) / 2) + 0.5
            rRect2.Height = rRect2.Height + ((Effect - 21) / 2) + 0.5
            hStatus = GdipCreatePath(0, pPath2) '0=FillModeAlternate
            GdipAddPathString pPath2, auxt$, -1, pFontFamily, FontStyle&, FontSize, rRect2, hFormat
    
            GdipCreatePen1 ConvertColor(vbBlack, 25), 3, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath2)
    
            GdipCreateSolidFill ConvertColor(vbBlack, 25), pBrush
            hStatus = GdipFillPath(gdipGraphics&, pBrush, pPath2)
    
            GdipDeleteBrush pBrush
            GdipDeletePath (pPath2)
        Case 25, 26, 27, 28 'Black_Outline_1/2_75/100p
            Select Case Val(Effect)
            Case 25
                AuxEff = 75: auxSize = 1
            Case 26
                AuxEff = 100: auxSize = 1
            Case 27
                AuxEff = 75: auxSize = 2
            Case 28
                AuxEff = 100: auxSize = 2
            End Select
            GdipCreatePen1 ConvertColor(vbBlack, AuxEff), auxSize, UnitPixel, pPen
            GdipSetPenLineJoin pPen, LineJoinRound
            hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
        End Select
    End If
    
    'Create brush
    hStatus = GdipCreateSolidFill(ConvertColor(ccolor, Opacity), pBrush)
    'hStatus = GdipDrawString(gdipGraphics&, StrPtr(auxt$), Len(auxt$), gdipFont, rRect, hFormat, pBrush)
    hStatus = GdipDrawString(gdipGraphics&, StrPtr(auxt$), -1, gdipFont, rRect, hFormat, pBrush)

    If (Rotation <> 0) Then
        GdipResetWorldTransform gdipGraphics
    End If

CleanUp:
    ' // Cleanup
    If pBrush Then GdipDeleteBrush pBrush
    If gdipFont Then GdipDeleteFont (gdipFont)
    If pFontFamily Then GdipDeleteFontFamily (pFontFamily)
    pFontFamily = 0
    If pPen Then GdipDeletePen (pPen)
    If pPath Then GdipDeletePath (pPath)
    If hFormat Then GdipDeleteStringFormat (hFormat)
    
    Exit Sub
Err:
    Debug.Print ("Gdip.DrawText_DRAWSTRINGAPI Err: " & Err.Description)
End Sub


'================================================
'Draw the button caption using paths
'================================================
'Draw Text Converting normal text to unicode and replacing /// to linebreaks
Public Sub DrawText(sText As String, X!, Y!, XWidth!, YHeight!, ccolor&, Optional Opacity& = 100, _
     Optional HAlign As Long = 0, Optional VAlign As Long = 0, _
     Optional Effect As Long = 0, Optional Rotation! = 0, Optional fFont As StdFont = Nothing, Optional NoWrap As Boolean)
On Error GoTo Err:
Dim auxt$
    
    If (sText = "") Then Exit Sub
    
    'Support for multiple 2bytes chars
    auxt$ = Replace(sText, "///", vbCrLf)
    auxt$ = Replace(auxt$, "//\/", "///")
    auxt$ = StrConv(auxt$, vbUnicode)
    DrawTextUnicode auxt$, X!, Y!, XWidth!, YHeight!, ccolor&, Opacity&, HAlign, VAlign, Effect, Rotation, fFont, NoWrap

    Exit Sub
Err:
    Debug.Print ("Gdip.DrawText Err: " & Err.Description)
End Sub

'Special version to draw Font Awesome Icons (Text should be the char code, Example: "F013" )
Public Sub DrawTextFA(sTextFA As String, X!, Y!, XWidth!, YHeight!, ccolor&, Optional Opacity& = 100, _
     Optional HAlign As Long = 0, Optional VAlign As Long = 0, _
     Optional Effect As Long = 0, Optional Rotation! = 0, Optional ByVal fFont As StdFont = Nothing, Optional NoWrap As Boolean)
On Error GoTo Err:
'    'Invert the byteorder of FontAwesome cheat tables
'    sTextFA="F013"
    Dim auxt$
    auxt$ = CharvalToUnicode(sTextFA)
    
    DrawTextUnicode auxt$, X!, Y!, XWidth!, YHeight!, ccolor&, Opacity&, HAlign, VAlign, Effect, Rotation, fFont, NoWrap

    Exit Sub
Err:
    Debug.Print ("Gdip.DrawTextFA Err: " & Err.Description)
End Sub


'Calculate the size for the text using all screen
'Return values in retHeight!, retHeight!, LinesFilled&
Public Sub CalcTextSize(lHDC&, sText As String, ByRef retWidth!, ByRef retHeight!, ByRef LinesFilled&, Optional fFont As StdFont = Nothing, Optional ByVal MaxWidth! = 9999)
Dim auxt$
    'Support for multiple 2bytes chars
    auxt$ = Replace(sText, "///", vbCrLf)
    auxt$ = StrConv(auxt$, vbUnicode)
    
    CalcTextSizeU lHDC&, auxt$, retWidth!, retHeight!, LinesFilled&, fFont, MaxWidth
End Sub

Public Sub DrawTextUnicode(sTextU As String, X!, Y!, XWidth!, YHeight!, ccolor&, Optional Opacity& = 100, _
     Optional HAlign As Long = 0, Optional VAlign As Long = 0, _
     Optional Effect As eSB_Caption_Effect = 0, Optional Rotation! = 0, Optional fFont As StdFont = Nothing, Optional NoWrap As Boolean)
On Error GoTo Err:
    Dim rRect As RectF
    Dim strFontName As String, FontSize As Single, FontStyle&
    Dim bPreservePGraphics As Boolean
    Dim hStatus As Long
    Dim pPath As Long
    Dim pPen As Long
    Dim pBrush As Long
    Dim pFontFamily As Long
    Dim gdipFont As Long
    Dim hFormat As Long
    Dim i&
    Dim pPath2, rRect2 As RectF, auxPsize&, auxEffStart&, offsetX&
    Dim AuxEff&, auxSize&
    Dim HalfW!, HalfH!
    Dim OldPixelOffsetMode&

    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics = 0 Then Err.Raise &H80044010, TypeName(Me), "CreateGraphics() not called"
    
    'Set Quality for Paths based on TextQuality
    SetGlobalQuality m_GlobalQualityTXT, -1
    
    If (fFont Is Nothing) Then
        If (mFont Is Nothing) Then Set mFont = New StdFont
        Set fFont = mFont
    End If
    
    'Paths make font smaller, create a new font trying to compensate so size is equal to normal fonts
    Dim renderFont As New StdFont
    With renderFont
        .Name = fFont.Name
        .Size = fFont.Size * fontMult
        .Bold = fFont.Bold
        .Italic = fFont.Italic
        .Charset = fFont.Charset
        .Underline = fFont.Underline
    End With
    
    rRect.Left = X
    rRect.Top = Y
    rRect.Width = XWidth!
    rRect.Height = YHeight!
    
    hStatus = GdipStringFormatGetGenericDefault(hFormat)
    GdipSetStringFormatAlign hFormat, HAlign
    GdipSetStringFormatLineAlign hFormat, VAlign
    
    If (NoWrap) Then GdipSetStringFormatFlags hFormat, StringFormatFlagsNoWrap
    GdipSetStringFormatTrimming hFormat, StringTrimmingEllipsisCharacter
    GdipSetStringFormatHotkeyPrefix hFormat, HotkeyPrefixShow
    
    'strFontName = "Font Awesome 5 Free Solid" / "Segoe UI"
    strFontName = renderFont.Name
    FontSize = renderFont.Size '24
    
    'FONT REPLACES
    If (strFontName = "MS Sans Serif") Then strFontName = "Microsoft Sans Serif"
    
    'FontStyle
    If (renderFont.Bold) Then FontStyle = FontStyleBold
    If (renderFont.Italic) Then FontStyle = FontStyle Or FontStyleItalic
    If (renderFont.Underline) Then FontStyle = FontStyle Or FontStyleUnderline

    If (GdipCreateFontFamilyFromName(StrConv(strFontName, vbUnicode), 0, pFontFamily)) Then
        If (hFontCollection) Then
            If (GdipCreateFontFamilyFromName(StrConv(strFontName, vbUnicode), hFontCollection, pFontFamily)) Then
                GdipCreateFontFamilyFromName StrConv("Microsoft Sans Serif", vbUnicode), 0, pFontFamily
            End If
        Else
            GdipCreateFontFamilyFromName StrConv("Microsoft Sans Serif", vbUnicode), 0, pFontFamily
        End If
    End If
    If (pFontFamily = 0) Then
        Debug.Print "DrawText_DRAWSTRINGAPI Can't create FontFamily: [" & strFontName & "]"
        GoTo CleanUp
    End If

    hStatus = GdipCreateFont(pFontFamily, FontSize, FontStyle, GpUnit.UnitPoint, gdipFont)
    If (hStatus <> 0) Then
        Debug.Print "DrawTextUnicode Can't create Font: [" & strFontName & "]"
        GoTo CleanUp
    End If
    
    Dim auxt$
    auxt$ = sTextU
    
    'Text rotation?
    If (Rotation <> 0) Then
        'Calc the area of the text to know where to position the center of the rotation
        Dim BoundRectF As RectF, CodepointsFitted&, LinesFilled&
        GdipMeasureString gdipGraphics&, StrPtr(auxt$), Len(auxt$), gdipFont, rRect, hFormat, BoundRectF, CodepointsFitted, LinesFilled
        
        ''Make centered square area (seems to be not necesary at all)
        'Dim diff!
        'If (BoundRectF.Height > BoundRectF.Width) Then
        '    diff! = (BoundRectF.Height - BoundRectF.Width)
        '    BoundRectF.Width = BoundRectF.Width + diff!
        '    BoundRectF.Left = BoundRectF.Left - (diff! / 2)
        'ElseIf (BoundRectF.Height < BoundRectF.Width) Then
        '    diff! = (BoundRectF.Width - BoundRectF.Height)
        '    BoundRectF.Height = BoundRectF.Height + diff!
        '    BoundRectF.Top = BoundRectF.Top - (diff! / 2)
        'End If
                
        'Debug area used
        'DrawRect vbCyan, 60, 1, BoundRectF.Left, BoundRectF.Top, BoundRectF.Width, BoundRectF.Height, 2
        
        
        'Rotate and translate
        HalfW = (BoundRectF.Width / 2)
        HalfH = (BoundRectF.Height / 2)
        GdipRotateWorldTransform gdipGraphics, Rotation!, 0
        GdipTranslateWorldTransform gdipGraphics, BoundRectF.Left + HalfW, BoundRectF.Top + HalfH, 1
        
        'Set the new area to draw
        rRect.Left = -HalfW
        rRect.Top = -HalfH
        rRect.Width = BoundRectF.Width
        rRect.Height = BoundRectF.Height

    End If
    
    'Create a path with the string
    hStatus = GdipCreatePath(0, pPath) '0=FillModeAlternate
    GdipAddPathString pPath, auxt$, -1, pFontFamily, FontStyle&, FontSize, rRect, hFormat
    
   
    'Effects
    '1-5 Black Outline (20%) (size 1-5)
    '6-10 Black Outline (50%)  (size 1-5)
    '11 White Outline (25%) size 2
    '12-15 Same color Outline (25%) (size 1-4)
    '16-21 Black Bottom Shadow (25%-50%) (Size 1-3)
    '22-24 Black Bottom Shadow with border shadow (1-3)
    Select Case Val(Effect)
    Case 1, 2, 3, 4, 5
        GdipCreatePen1 ConvertColor(vbBlack, 20), Effect, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
    Case 6, 7, 8, 9, 10
        GdipCreatePen1 ConvertColor(vbBlack, 50), Effect - 5, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
    Case 11
        GdipCreatePen1 ConvertColor(vbWhite, 25), 2, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
    Case 12, 13, 14, 15
        GdipCreatePen1 ConvertColor(ccolor, 25), Effect - 11, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
    Case 16, 17, 18, 19, 20, 21
        If (Effect > 15 And Effect < 19) Then
            auxEffStart& = 15
            auxPsize& = 1
        Else
            auxEffStart& = 18
            auxPsize& = 2
        End If
        rRect2 = rRect
        rRect2.Top = rRect2.Top + ((Effect - auxEffStart&) / 2) + 0.5
        rRect2.Height = rRect2.Height + ((Effect - auxEffStart&) / 2) + 0.5
        hStatus = GdipCreatePath(0, pPath2) '0=FillModeAlternate
        GdipAddPathString pPath2, auxt$, -1, pFontFamily, FontStyle&, FontSize, rRect2, hFormat

        GdipCreateSolidFill ConvertColor(vbBlack, 25 * auxPsize&), pBrush
        hStatus = GdipFillPath(gdipGraphics&, pBrush, pPath2)

        GdipDeleteBrush pBrush
        GdipDeletePath (pPath2)
        
    Case 22, 23, 24
        'Solid Shadow and border
        rRect2 = rRect
        rRect2.Top = rRect2.Top + ((Effect - 21) / 2) + 0.5
        rRect2.Height = rRect2.Height + ((Effect - 21) / 2) + 0.5
        hStatus = GdipCreatePath(0, pPath2) '0=FillModeAlternate
        GdipAddPathString pPath2, auxt$, -1, pFontFamily, FontStyle&, FontSize, rRect2, hFormat

        GdipCreatePen1 ConvertColor(vbBlack, 25), 3, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath2)

        GdipCreateSolidFill ConvertColor(vbBlack, 25), pBrush
        hStatus = GdipFillPath(gdipGraphics&, pBrush, pPath2)

        GdipDeleteBrush pBrush
        GdipDeletePath (pPath2)
    Case 25, 26, 27, 28 'Black_Outline_1/2_75/100p
        Select Case Val(Effect)
        Case 25
            AuxEff = 75: auxSize = 1
        Case 26
            AuxEff = 100: auxSize = 1
        Case 27
            AuxEff = 75: auxSize = 2
        Case 28
            AuxEff = 100: auxSize = 2
        End Select
        GdipCreatePen1 ConvertColor(vbBlack, AuxEff), auxSize, UnitPixel, pPen
        GdipSetPenLineJoin pPen, LineJoinRound
        hStatus = GdipDrawPath(gdipGraphics&, pPen, pPath)
    End Select
    
    'Create brush
    hStatus = GdipCreateSolidFill(ConvertColor(ccolor, Opacity), pBrush)
    
    'Draw Text using paths (more smooth than GdipDrawString)
    hStatus = GdipFillPath(gdipGraphics&, pBrush, pPath)
    ''GdipSetPenColor(gdipPen, ForeColorARGB)
    'hStatus = GdipDrawString(gdipGraphics&, StrPtr(auxt$), Len(auxt$), gdipFont, rRect, 0, pBrush)
    'TextOut hDC, 0, 0, StrPtr(auxt$), Len(auxt$)

    If (Rotation <> 0) Then
        GdipResetWorldTransform gdipGraphics
    End If

CleanUp:
    ' // Cleanup
    If pBrush Then GdipDeleteBrush pBrush
    If gdipFont Then GdipDeleteFont (gdipFont)
    If pFontFamily Then GdipDeleteFontFamily (pFontFamily)
    pFontFamily = 0
    If pPen Then GdipDeletePen (pPen)
    If pPath Then GdipDeletePath (pPath)
    If hFormat Then GdipDeleteStringFormat (hFormat)
    SetGlobalQualityRestore
    
    Exit Sub
Err:
    Debug.Print ("Gdip.DrawTextUnicode Err: " & Err.Description)
End Sub

'Calculate the size for the text using all screen
'Return values in retX,retY,retWidth,retHeight
Public Sub CalcTextSizeU(lHDC&, sTextU As String, ByRef retWidth!, ByRef retHeight!, ByRef LinesFilled&, Optional fFont As StdFont = Nothing, Optional ByVal MaxWidth! = 9999)
On Error GoTo Err:
Dim auxt$, strFontName$, hStatus&
Dim pFontFamily As Long, FontSize&, FontStyle&, lgdipGraphics&
Dim gdipFont As Long
Dim hFormat As Long
Dim rRect As RectF
    
    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If (GdipCreateFromHDC(lHDC&, lgdipGraphics&)) Then Err.Raise &H80044000, TypeName(Me), "CalcTextSizeU failed to create Graphics"
        
    If (fFont Is Nothing) Then
        If (mFont Is Nothing) Then Set mFont = New StdFont
        Set fFont = mFont
    End If
    
    strFontName = fFont.Name
    FontSize = fFont.Size '24
    
    'FontStyle
    If (fFont.Bold) Then FontStyle = FontStyleBold
    If (fFont.Italic) Then FontStyle = FontStyle Or FontStyleItalic
    If (fFont.Underline) Then FontStyle = FontStyle Or FontStyleUnderline
    
    hStatus = GdipStringFormatGetGenericDefault(hFormat)
    GdipSetStringFormatAlign hFormat, pStringAlignment.pStringAlignmentnear
    GdipSetStringFormatLineAlign hFormat, pStringAlignment.pStringAlignmentnear
    
    hStatus = GdipCreateFontFamilyFromName(StrConv(strFontName, vbUnicode), 0, pFontFamily)
    If (hStatus <> 0) Then
        Debug.Print "CalcTextSizeU Can't create FontFamily: [" & strFontName & "]"
        GoTo CleanUp
    End If

    hStatus = GdipCreateFont(pFontFamily, FontSize, FontStyle, GpUnit.UnitPoint, gdipFont)
    If (hStatus <> 0) Then
        Debug.Print "CalcTextSizeU Can't create Font: [" & strFontName & "]"
        GoTo CleanUp
    End If
    
    auxt$ = sTextU
    
    rRect.Left = 0: rRect.Top = 0
    rRect.Width = MaxWidth: rRect.Height = 9999
    
    'Calc the area of the text
    Dim BoundRectF As RectF, CodepointsFitted&
    GdipMeasureString lgdipGraphics&, StrPtr(auxt$), Len(auxt$), gdipFont, rRect, hFormat, BoundRectF, CodepointsFitted, LinesFilled
    
    retWidth = BoundRectF.Width * 1.03  ' Magic Number to fix the difference for autosize
    retHeight = BoundRectF.Height
    
    'Debug.Print "Ret: " & retWidth & "|" & retHeight & "| Lines: " & LinesFilled

CleanUp:
    ' // Cleanup
    If gdipFont Then GdipDeleteFont (gdipFont)
    If pFontFamily Then GdipDeleteFontFamily (pFontFamily)
    pFontFamily = 0
    If hFormat Then GdipDeleteStringFormat (hFormat)
    If (lgdipGraphics) Then GdipDeleteGraphics lgdipGraphics
    Exit Sub
Err:
    Debug.Print ("Gdip.CalcTextSizeU Err: " & Err.Description)
End Sub


Private Function ChrW2(ByVal CharCode As Long) As String
  Const POW10 As Long = 2 ^ 10
  If CharCode <= &HFFFF& Then ChrW2 = ChrW$(CharCode) Else _
                              ChrW2 = ChrW$(&HD800& + (CharCode And &HFFFF&) \ POW10) & _
                                      ChrW$(&HDC00& + (CharCode And (POW10 - 1)))
End Function

Public Sub ReleaseGraphics()
    If GdipToken = 0 Then Err.Raise &H80044000, TypeName(Me), "GDI+ failed to start"
    If gdipGraphics <> 0 Then gdipStatus = GdipDeleteGraphics(gdipGraphics)
    If gdipFont <> 0 Then GdipDeleteFont (gdipFont)
End Sub

Private Sub GetDpiOfGraphics()
    Dim DpiX As Single
    Dim DpiY As Single

    gdipStatus = GdipGetDpiX(gdipGraphics, DpiX)
    If gdipStatus <> Ok Then
        Err.Raise &H80044B00, _
                  TypeName(Me), _
                  "GdipGetDpiX error " & CStr(gdipStatus)
    End If
    gdipStatus = GdipGetDpiY(gdipGraphics, DpiY)
    If gdipStatus <> Ok Then
        Err.Raise &H80044B10, _
                  TypeName(Me), _
                  "GdipGetDpiY error " & CStr(gdipStatus)
    End If
    TwipsPerPixelX = 1440 / DpiX
    TwipsPerPixelY = 1440 / DpiY
End Sub

Private Function scaleX(ByVal TwipsX As Single) As Long
    scaleX = Int(TwipsX / TwipsPerPixelX + 0.5!)
End Function
Private Function scaleY(ByVal TwipsY As Single) As Long
    scaleY = Int(TwipsY / TwipsPerPixelY + 0.5!)
End Function

Private Function UnScaleX(ByVal PixelsX As Long) As Single
    UnScaleX = PixelsX * TwipsPerPixelX
End Function
Private Function UnScaleY(ByVal PixelsY As Long) As Single
    UnScaleY = PixelsY * TwipsPerPixelY
End Function



Private Sub Class_Initialize()
    GdipStartupInput.GdiPlusVersion = 1
    GdiplusStartup GdipToken, GdipStartupInput, WIN32_NULL
    If GdipToken <> 0 Then
        hFontCollection = ReadValue(&HFC)
        'DrawWidth = 1
        'FillColor = -1 'Transparent.
        'ForeColor = vbBlack
        'If (mFont Is Nothing) Then Set mFont = New StdFont
    Else
        MsgBox "Error initializing GDI+", vbCritical
    End If
    'Randomize Timer
    
    
End Sub

Private Sub Class_Terminate()
    If Blur_hDCMemory <> 0 Then DestroyBlurZoomBuffer
    If gdipBrush <> 0 Then GdipDeleteBrush gdipBrush
    If gdipPen <> 0 Then GdipDeletePen gdipPen
    If gdipFont <> 0 Then GdipDeleteFont gdipFont
    If GdipToken <> 0 Then GdiplusShutdown GdipToken
End Sub

'las dos funciones a continuacion son de Cobein y con algunas modificaciones de Leandro Ascierto,
'las he utilizado para crear una bandera publica sin tener que agregar un modulo publico.
Private Function WriteValue(ByVal lProp As Long, ByVal lValue As Long) As Boolean
    Dim lFlagIndex As Long
    Dim i       As Long
    Dim lIndex  As Long: lIndex = -1
    
    For i = 0 To 64 - 1 ' 64=TLS_MINIMUM_AVAILABLE
        If TlsGetValue(i) = lProp Then
            lIndex = i + 1
            Exit For
        End If
    Next

    If lIndex = -1 Then
        Do
            lFlagIndex = TlsAlloc '// Find two consecutive slots
            lIndex = TlsAlloc
            If lIndex >= 64 Then Exit Function '64 = TLS_MINIMUM_AVAILABLE
        Loop While Not lFlagIndex + 1 = lIndex
        Call TlsSetValue(lFlagIndex, lProp)
        Call TlsSetValue(lIndex, lValue)
        WriteValue = True
    Else
        Call TlsSetValue(lIndex, lValue)
    End If
End Function
Private Function ReadValue(ByVal lProp As Long, Optional Default As Long) As Long
    Dim i       As Long
    For i = 0 To 64 - 1 '64 = TLS_MINIMUM_AVAILABLE
        If TlsGetValue(i) = lProp Then
            ReadValue = TlsGetValue(i + 1)
            Exit Function
        End If
    Next
    ReadValue = Default
End Function


'*1
Public Function OpenURL(ByVal sUrl As String) As Byte()
'****************************************************
'PURPOSE:       Returns Contents (including all HTML) from a web page
'PARAMETER:     sURL (e.g., http://www.freevbcode.com)
'RETURN VALUE:  Contents of requested page, or empty string if sURL is not available
'COMMENTS:  This is an alternative to using the Internet Transfer
'           Control 's OpenURL method.  That control has a bug
'           Whereby not all the contents of the page will be
'           returned in certain circumstances
'*****************************************************
Dim hOpen               As Long
Dim hOpenUrl            As Long
Dim bDoLoop             As Boolean
Dim bRet                As Boolean
Dim sReadBuffer         As String * 2048
Dim lNumberOfBytesRead  As Long
Dim lNumberOfBytesTotal  As Long
Dim sBuffer             As String
Dim b() As Byte

    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    hOpenUrl = InternetOpenUrl(hOpen, sUrl, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
    
    RaiseEvent OpenURLStart(sUrl)
    bDoLoop = True
    While bDoLoop
        sReadBuffer = vbNullString
        bRet = InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
        sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
        lNumberOfBytesTotal = lNumberOfBytesTotal + lNumberOfBytesRead
        If Not CBool(lNumberOfBytesRead) Then bDoLoop = False
        RaiseEvent OpenURLDataReceiving(lNumberOfBytesTotal)
        DoEvents
    Wend
      
    If hOpenUrl <> 0 Then InternetCloseHandle (hOpenUrl)
    If hOpen <> 0 Then InternetCloseHandle (hOpen)
    
    'OpenURL = sBuffer
    OpenURL = StrConv(sBuffer, vbFromUnicode)
    RaiseEvent OpenURLFinished(OpenURL)

End Function


'Add transparency to a color (opacity 0-100)
Private Function ConvertColor(nColor&, nOpacity&) As Long
    Dim BGRA(0 To 3) As Byte
    Dim iColor As Long
    
    If (nOpacity < 0) Then nOpacity = 0
    If (nOpacity > 100) Then nOpacity = 100
    
    OleTranslateColor nColor, 0&, iColor
    
    BGRA(3) = CByte((nOpacity / 100) * 255)
    BGRA(0) = ((iColor \ &H10000) And &HFF)
    BGRA(1) = ((iColor \ &H100) And &HFF)
    BGRA(2) = (iColor And &HFF)
    CopyMemory ConvertColor, BGRA(0), 4&
End Function

'make a color lighter or darker
Public Function HighlightColor(ByRef nColor&, Optional ByRef diff& = 50) As Long
Dim aux&, n&
    n& = Abs(diff)
    diff = Sgn(diff) * RGB(n, n, n)
    aux& = nColor& + diff
    'rgb(255,255,255) = 16777215
    If (diff < 0) And (aux < 0) Then aux = nColor& - diff
    If (diff > 0) And (aux > 16777215) Then aux = nColor& - diff
    
    HighlightColor = RangeL(aux, 0, 16777215)
    
End Function




'Draw border of rectangle (support rounded)
Public Sub DrawRect(ByVal nColor As Long, ByVal mOpacity As Long, ByVal nDrawnWidth As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, Optional ByVal nRoundSize As Long = 10, Optional ByVal lPenAlignment As PenAlignment = PenAlignmentCenter)
Dim x1&, X2&, y1&, Y2&
Dim hPen&, Path&, diameter&
    
    If (mOpacity = 0) Then Exit Sub
    If (nDrawnWidth = 0) Then Exit Sub
    
    x1 = X
    X2 = X + nWidth
    y1 = Y
    Y2 = Y + nHeight
    
    'Create path with the shape
    pvCreateRectPathI x1, y1, X2, Y2, nRoundSize, Path

    GdipCreatePen1 ConvertColor(nColor, mOpacity), nDrawnWidth, UnitPixel, hPen
    If (lPenAlignment <> PenAlignmentCenter) Then GdipSetPenMode hPen, lPenAlignment

'    Select Case PenType
'        Case PenTypeSolidColor
'            GdipCreatePen1 ConvertColor(nColor, mOpacity), nDrawnWidth, UnitPixel, pen
'        Case PenTypeTextureFill
'            If bFileExists(sImageBorder) Then
'                GdipLoadImageFromFile StrConv(sImageBorder, vbUnicode), Img
'                GdipCreateTexture Img, WrapModeTile, brush
'                GdipCreatePen2 brush, PenWidth, UnitPixel, pen
'                GdipDeleteBrush brush
'            End If
'        Case PenTypeHatchFill
'        Case PenTypeLinearGradient
'        Case PenTypePathGradient
'        Case Else
'          'None
'    End Select

    GdipDrawPath gdipGraphics, hPen, Path

    'Cleanup
    GdipDeletePath Path
    If (hPen) Then GdipDeletePen hPen

End Sub

'Draw shadow of rectangle (support rounded)
Public Sub DrawShadow(ByVal nColor As Long, ByVal mOpacity As Long, ByVal nShadowWidth As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, Optional ByVal nRoundSize As Long = 10, Optional shadowStyle As eSB_Shadow_Style = Gradual_Alpha_st2)
Dim x1&, X2&, y1&, Y2&
Dim hPen&, Path&, hBrush&
Dim i&, tmpRound&, auxF!, auxStep&
Dim pt1 As POINTL, pt2 As POINTL

'Dim tMatrix&
    
    'Early exit if dont need to draw anything
    If (mOpacity = 0) Or (shadowStyle = 0) Then Exit Sub
    If (nShadowWidth < 1) Then nShadowWidth = 1
    
    x1 = X
    X2 = X + nWidth
    y1 = Y
    Y2 = Y + nHeight
    
'    'Check for full rounded
'    If (nRoundSize > 20) And (y2 - y1 < nRoundSize * 3) Then
'        tmpRound& = nRoundSize / 5
'    Else
'        tmpRound& = nRoundSize - 1
'    End If
    
    GdipSetSmoothingMode gdipGraphics, SmoothingModeAntiAlias
    GdipSetCompositingQuality gdipGraphics, CompositingQualityHighQuality
    'GdipSetCompositingQuality gdipGraphics, CompositingQualityGammaCorrected
    
    'Create path with the shape
    pvCreateRectPathI x1, y1, X2, Y2, nRoundSize, Path
    
    If (nShadowWidth < 0) Then nShadowWidth = 0

    Select Case shadowStyle
    Case 0
        'No shadow = 0
    Case 1
        'Fixed Shadow = 1
        For i = nShadowWidth To 1 Step -2
            GdipCreatePen1 ConvertColor(nColor, mOpacity), i, UnitPixel, hPen
            GdipDrawPath gdipGraphics, hPen, Path
            GdipDeletePen hPen
        Next i
        
    Case 2, 3, 4, 5
        'Gradual Alpha st1 = 2
        'Gradual Alpha st2 = 3
        'Gradual Alpha st3 = 4
        'Gradual Alpha st4 = 5
        auxF! = mOpacity / nShadowWidth
        auxStep& = (shadowStyle - 1) * -1
        For i = nShadowWidth To 1 Step auxStep&
            GdipCreatePen1 ConvertColor(nColor, 2 + (mOpacity - (i * auxF!))), 1 + i, UnitPixel, hPen
            GdipDrawPath gdipGraphics, hPen, Path
            GdipDeletePen hPen
        Next i
    
    Case 6
        'Inverse Gradual  = 6
        auxF! = mOpacity / nShadowWidth
        For i = 1 To nShadowWidth Step 3
            GdipCreatePen1 ConvertColor(nColor, 2 + ((i * auxF!))), 1 + i, UnitPixel, hPen
            GdipDrawPath gdipGraphics, hPen, Path
            GdipDeletePen hPen
        Next i
        
    Case 7
        'Simple 1 Color = 7
        GdipCreatePen1 ConvertColor(nColor, mOpacity), nShadowWidth, UnitPixel, hPen
        GdipDrawPath gdipGraphics, hPen, Path
        GdipDeletePen hPen
        
    Case 8, 9, 10, 11
        'Gradient Up = 8
        'Gradient Down = 9
        'Gradient Left = 10
        'Gradient Right = 11
        Select Case shadowStyle
        Case 8:  pt1.X = x1: pt1.Y = y1:   pt2.X = x1: pt2.Y = Y2
        Case 9:  pt1.X = x1: pt1.Y = Y2:   pt2.X = x1: pt2.Y = y1
        Case 10:  pt1.X = x1: pt1.Y = y1:   pt2.X = X2: pt2.Y = y1
        Case 11:  pt1.X = X2: pt1.Y = y1:   pt2.X = x1: pt2.Y = y1
        End Select
        GdipCreateLineBrushI pt1, pt2, ConvertColor(0, 0), ConvertColor(nColor, mOpacity), WrapModeTile, hBrush
        
    Case 12, 13
        'Grandient UpDown = 12
        'Gradient LefRight = 13
        Select Case shadowStyle
        Case 12:  pt1.X = x1: pt1.Y = y1:   pt2.X = x1: pt2.Y = Y2
        Case 13:  pt1.X = x1: pt1.Y = y1:   pt2.X = X2: pt2.Y = y1
        End Select
        
        Dim fac(3) As Single
        Dim fpos(3) As Single
        fac(0) = 0!: fac(1) = 0.1!: fac(2) = 0.9!: fac(3) = 1!
        fpos(0) = 0!: fpos(1) = 0.8!: fpos(2) = 0.9!: fpos(3) = 1!
        
        GdipCreateLineBrushI pt1, pt2, ConvertColor(0, 0), ConvertColor(nColor, mOpacity), WrapModeTile, hBrush
            GdipSetLineBlend hBrush, fac(0), fpos(0), 4
        GdipFillPath gdipGraphics, hBrush, Path
        GdipDeleteBrush hBrush

        GdipCreateLineBrushI pt2, pt1, ConvertColor(0, 0), ConvertColor(nColor, mOpacity), WrapModeTile, hBrush
            GdipSetLineBlend hBrush, fac(0), fpos(0), 4
    End Select
    
    
    GdipCreateSolidFill ConvertColor(nColor, mOpacity), hBrush
    
    If hBrush Then
        GdipFillPath gdipGraphics, hBrush, Path
        GdipDeleteBrush hBrush
    End If
    


    'Cleanup
    GdipDeletePath Path
    If (hPen) Then GdipDeletePen hPen

End Sub

'=================================================================
'Draw filled rectangles (rounded,gradient,textured,alpha)
'Note: If used for animation take into account that texture fill with opacity other than 100 is slower.
'=================================================================
Public Sub FillRect(ByVal nColor As Long, ByVal mOpacity As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, Optional ByVal nRoundSize As Long = 10, _
Optional ByVal BrushType As FillBrushType = FillBrushType.fBrushTypeSolidColor, _
Optional ByVal nColor2 As Long = 0, Optional ByVal mOpacity2 As Long = 0, _
Optional ByVal Angle As Single = 0, Optional ByRef sImageFill As Variant, _
Optional lHatchStyle As HatchStyle = HatchStyleDottedGrid, _
Optional ByRef textureDisplacementX! = 0, Optional ByRef textureDisplacementY! = 0, _
Optional ByVal GradientBlendPoint! = 0.5 _
)
On Error GoTo Err:
Dim hBrush&, Path&, diameter&
Dim pt1 As POINTL, pt2 As POINTL
Dim x1&, X2&, y1&, Y2&
Dim TempImg&, bDispose As Boolean ' flag to dispose the temp image
Dim auxEscX!, auxEscY!, imgW!, imgH!
Dim fac(2) As Single 'For gradient Blend
Dim fpos(2) As Single
    
    'Exit if nothing to draw
    If (mOpacity = 0) And (BrushType = FillBrushType.fBrushTypeSolidColor) Then Exit Sub
    If (BrushType = FillBrushType.fBrushTypeTransparent) Then Exit Sub
    If (mOpacity = 0) And (mOpacity2 = 0) Then Exit Sub
    If (nWidth = 0) Or (nHeight = 0) Then Exit Sub
    
    x1 = X
    X2 = X + nWidth
    y1 = Y
    Y2 = Y + nHeight
    
    'Create path with the shape
    pvCreateRectPathI x1, y1, X2, Y2, nRoundSize, Path

    'Create brush
    Select Case BrushType
        Case fBrushTypeSolidColor
            GdipCreateSolidFill ConvertColor(nColor, mOpacity), hBrush
            
        Case fBrushTypeLinearGradient
            'pt1.x = x1: pt1.Y = y1
            'pt2.x = x1: pt2.Y = y2
            'GdipCreateLineBrushI pt1, pt2, ConvertColor(nColor, mOpacity), ConvertColor(nColor2, mOpacity2), WrapModeTile, hBrush
            Dim r As RECT
            r.Left = X: r.Top = Y
            r.Right = nWidth: r.Bottom = nHeight
            GdipCreateLineBrushFromRectWithAngleI r, ConvertColor(nColor, mOpacity), ConvertColor(nColor2, mOpacity2), Angle, False, WrapModeTile, hBrush

            If (GradientBlendPoint <> 0.5) Then
                fac(0) = 0!: fac(1) = 0.5!: fac(2) = 1!
                fpos(0) = 0!: fpos(1) = GradientBlendPoint!: fpos(2) = 1!
                GdipSetLineBlend hBrush, fac(0), fpos(0), 3
            End If
            
'            'How to set multiple blending pattern
'            Dim fac(3) As Single
'            Dim fpos(3) As Single
'            fac(0) = 0!: fac(1) = 0.4!: fac(2) = 0.6!: fac(3) = 1!
'            fpos(0) = 0!: fpos(1) = 0.2!: fpos(2) = 0.8!: fpos(3) = 1!
'            GdipSetLineBlend hBrush, fac(0), fpos(0), 4
            
        Case fBrushTypeCircularGradient
            
            'First Fill with 2nd gradient color so if we move the circle with textureDisplacementX/Y
            'it will still be colored
            GdipCreateSolidFill ConvertColor(nColor2, mOpacity), hBrush
            GdipFillPath gdipGraphics, hBrush, Path
            GdipDeleteBrush hBrush
            
            'Now we add the circular path
            Dim PathCircle
            GdipCreatePath 0, PathCircle
            GdipAddPathEllipseI PathCircle, X - (nWidth / 5) + CLng(textureDisplacementX), Y - (nHeight / 5) + CLng(textureDisplacementY), nWidth + ((nWidth / 5) * 2), nHeight + ((nHeight / 5) * 2)

            GdipCreatePathGradientFromPath PathCircle, hBrush
            GdipSetPathGradientCenterColor hBrush, ConvertColor(nColor, mOpacity)
            GdipSetPathGradientSurroundColorsWithCount hBrush, ConvertColor(nColor2, mOpacity2), 1
            GdipDeletePath PathCircle

            
            If (GradientBlendPoint <> 0.5) Then
                fac(0) = 0!: fac(1) = 0.5!: fac(2) = 1!
                fpos(0) = 0!: fpos(1) = GradientBlendPoint!: fpos(2) = 1!
                GdipSetLineBlend hBrush, fac(0), fpos(0), 3
            End If

        Case fBrushTypeHatchFill
            GdipCreateHatchBrush lHatchStyle, ConvertColor(nColor, mOpacity), ConvertColor(nColor2, mOpacity2), hBrush

        Case fBrushTypePathGradient
            GdipCreatePathGradientFromPath Path, hBrush
            GdipSetPathGradientCenterColor hBrush, ConvertColor(nColor, mOpacity)
            GdipSetPathGradientSurroundColorsWithCount hBrush, ConvertColor(nColor2, mOpacity2), 1
            
            If (GradientBlendPoint <> 0.5) Then
                fac(0) = 0!: fac(1) = 0.5!: fac(2) = 1!
                fpos(0) = 0!: fpos(1) = GradientBlendPoint!: fpos(2) = 1!
                GdipSetLineBlend hBrush, fac(0), fpos(0), 3
            End If
        Case Else
            'Textured modes
            
            If (VarType(sImageFill) = vbLong) Then
                'pointer to an actual hImage passed, ready to use
                TempImg& = sImageFill
            Else
                'filename/bytes passsed, we need to load the image first
                bDispose = True
                TempImg& = LoadImg(sImageFill)
            End If

            If (TempImg&) <> 0 Then

'                'Apply alpha to texture
'                If (mOpacity <> 100) Then
'                    Dim ImgAttr&, CM(0 To 24) As Single
'                    GdipCreateImageAttributes ImgAttr
'                    CM(0) = 1: CM(6) = 1: CM(12) = 1: CM(24) = 1
'                    CM(18) = mOpacity / 100
'                    GdipSetImageAttributesColorMatrix ImgAttr&, 0&, 1&, CM(0), CM(0), 0&
'
'                End If

                Dim lWrapMode As WrapMode
                lWrapMode = WrapModeTile 'Default
                GdipGetImageDimension TempImg&, imgW!, imgH!
                
                Select Case BrushType
                Case fBrushTypeTextureFill
                    'GdipCreateTexture TempImg&, WrapModeTile, hBrush
                Case fBrushTypeTextureFillFlipXY
                    lWrapMode = WrapModeTileFlipXY
                    'GdipCreateTexture TempImg&, WrapModeTileFlipXY, hBrush
                Case fBrushTypeTextureFillFlipX
                    lWrapMode = WrapModeTileFlipX
                    'GdipCreateTexture TempImg&, WrapModeTileFlipX, hBrush
                Case fBrushTypeTextureFillFlipY
                    lWrapMode = WrapModeTileFlipY
                    'GdipCreateTexture TempImg&, WrapModeTileFlipY, hBrush
                End Select
                
                'No Alpha? use simpler brush create
                If (mOpacity = 100) Then
                    GdipCreateTexture TempImg&, lWrapMode, hBrush
                Else
                    Dim ImgAttr&, CM(0 To 24) As Single
                    GdipCreateImageAttributes ImgAttr
                    CM(0) = 1: CM(6) = 1: CM(12) = 1: CM(24) = 1
                    CM(18) = mOpacity / 100
                    GdipSetImageAttributesColorMatrix ImgAttr&, 0&, 1&, CM(0), CM(0), 0&
                    
                    GdipCreateTextureIA TempImg&, ImgAttr&, 0, 0, imgW, imgH, hBrush
                    GdipSetTextureWrapMode hBrush, lWrapMode
                End If
                
                'Effects after the brush was created
                Select Case BrushType
                Case fBrushTypeTextureFillStretch
                    auxEscX! = nWidth / imgW!
                    auxEscY! = nHeight / imgH!
                    GdipScaleTextureTransform hBrush, auxEscX!, auxEscY!, MatrixOrderAppend
                End Select
                
                If (Angle <> 0) Then
                    GdipRotateTextureTransform hBrush, Angle, MatrixOrderAppend
                End If
                    
                If (textureDisplacementX <> 0) Or (textureDisplacementY <> 0) Then
                    GdipTranslateTextureTransform hBrush, textureDisplacementX, textureDisplacementY, MatrixOrderAppend
                End If
                
                'Cleanup if needed
                If (ImgAttr) Then GdipDisposeImageAttributes ImgAttr
                If (bDispose) Then DestroyHImage TempImg&
            End If
    End Select


    If hBrush Then
        GdipFillPath gdipGraphics, hBrush, Path
    End If

    'Cleanup
    GdipDeletePath Path
    GdipDeleteBrush hBrush

    Exit Sub
Err:
    Debug.Print "FillRect Err: " & Err.Description
End Sub

'======================================
'Check value is in [min-max] range
'if not return the nearest one
'======================================
Public Function Range(ByRef value!, Min!, Max!) As Single
    If (value <= Min!) Then value! = Min!
    If (value >= Max!) Then value = Max!
    Range = value!
End Function
'======================================
'Check value is in [min-max] range
'if not return the nearest one
'(Long Version)
'======================================
Public Function RangeL(ByRef value&, Min&, Max&) As Long
    If (value <= Min) Then value = Min
    If (value >= Max) Then value = Max
    RangeL = value
End Function

'===================================
'Random number generation in range
'===================================
Public Function RN(Min!, Max!) As Single
    RN = (Max - Min + 0) * Rnd + Min
End Function

'================================================
'Random number generation in range (Long version)
'================================================
Public Function RNL(Min&, Max&) As Long
    RNL = (Max - Min + 0) * Rnd + Min
End Function


'=================================================================================
'Get path of target project where the ocx is being used
'=================================================================================
'Special thanks to Javier Balkenende for his help!
'Set from Project (in Form_Initialize) to resolve relative paths on runtime
'automatically get on ide
'Exmaple: For runtime set the app.path like this on the first form of project:
'Private Sub Form_Initialize()
'    'Set sGdip relative path resolution
'    SetAppPath App.Path
'End Sub
Public Property Get AppPath() As String
    'Debug.Print ">AppPath=" & GetExePath()
    If (BaseAppPath$ <> "") Then
        AppPath = BaseAppPath$
    Else
        If (COMPILE_AS_OCX) Then
            'USAR EN OCX
            AppPath = getClientAppPath 'App.Path
        Else
            'Solo cuando se usa como usercontrol
            AppPath = App.Path
        End If
        
    End If
End Property
'To set base path from the project
Public Property Let AppPath(sAppPath$)
    BaseAppPath$ = sAppPath
End Property



Private Function getClientAppPath() As String
Dim hProp As Long, mHwndIDEMain As Long
Dim iObjIDE As Object
Dim iObjVBE As Object
Dim iVBProject As Object
    Const vbext_pt_StandardExe = 0
    mHwndIDEMain = FindWindow("wndclass_desked_gsk", vbNullString)
    If (mHwndIDEMain <> 0) Then
        hProp = GetProp(mHwndIDEMain, "VBAutomation")
        If hProp <> 0 Then
            CopyMemory iObjIDE, hProp, 4&    '= VBIDE.Window
            On Error Resume Next
            Set iObjVBE = iObjIDE.VBE
            If Err.Number = 70 Then ' run time raises an access denied error
                ' IDE at run time
            Else
                ' IDE at desing time
                For Each iVBProject In iObjVBE.VBProjects
                    If iVBProject.type = vbext_pt_StandardExe Then
                        getClientAppPath = GetFolder(iVBProject.FileName)
                        Exit For
                    End If
                Next
            End If
            On Error GoTo 0
            CopyMemory iObjIDE, 0&, 4&
        End If
    Else
        getClientAppPath = GetFolder(GetExePath)
    End If
End Function

Private Function GetExePath() As String
    GetExePath = String$(255, Chr$(0))
    GetExePath = Left(GetExePath, GetModuleFileNameW(0, StrPtr(GetExePath), 255))
End Function

Private Function GetFolder(nPath As String) As String
Dim iPos As Long
    GetFolder = nPath
    iPos = InStrRev(nPath, "\")
    If iPos > 0 Then
        GetFolder = Left$(nPath, iPos)
    End If
End Function
'=================================================================================
'Get path of target project where the ocx is being used
'=================================================================================

'*3
'===========================================================================================
'Draw a Blur/Zoom Effect (Based on Acrylic blur by Leandro Ascierto)
'===========================================================================================
'Usage:
'   -Call CreateBlurZoomBuffer(...) on usercontrol blur activation
'   -Call BlurZoomCopyBackground to copy content behind the control (and other draws)
'   -Call DrawAcrylicBlur on UC Paint where you want. Every draw operation after it will
'    not be blured. (Draw background,border, then CopyBack and Blur, draw text so text its not blured)
'   -Not needed but you can call DestroyBlurZoomBuffer() on usercontrol blur deactivation
'    (to release resources inmediately)
'   -On UC Resize call CreateBlurZoomBuffer(...)
'Example:
'        If (m_BlurZoom) Then
'            .ReleaseGraphics 'To fix problem when drawing previous elements (they will be blured)
'            .BlurZoomCopyBackground
'            .CreateGraphics UserControl.hdc
'            .DrawBlurZoomPath ButtonArea.Left, ButtonArea.Top, ButtonArea.Right, ButtonArea.Bottom, m_BorderRoundedPX, m_Blur_Amount
'        End If
Public Sub DrawBlurZoom(ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, Optional nRoundSize& = 10, Optional BlurRadius& = 10, Optional ByRef Zoom! = 1)
Dim Path&, diameter&
Dim x1&, X2&, y1&, Y2&
    
    'Nothing to blur or zoom -> Exit
    If (BlurRadius& = 0) And (Zoom! = 1) Then Exit Sub
    
    x1 = X
    X2 = X + nWidth
    y1 = Y
    Y2 = Y + nHeight
    
    Call pvCreateRectPathI(x1, y1, X2, Y2, nRoundSize, Path)
    Call DrawBlurZoomPath(Path, BlurRadius, Zoom)
    GdipDeletePath Path&
End Sub
    
Private Sub DrawBlurZoomPath(ByRef hPath As Long, Optional ByRef BlurRadius& = 10, Optional ByRef Zoom! = 1)
Dim hBrush As Long
Dim hImage As Long
Dim hGraphics2 As Long, hImage2 As Long
Dim lEffect As Long
Dim bp As BlurParams
Dim rcSource As RectF
    
    If (hPath = 0) Then Debug.Print " >>> WARNING: sGdip.DrawBlurZoomPath: hPath = 0": Exit Sub

    If GdipCreateBitmapFromHBITMAP(Blur_hBmp, 0, hImage) = 0 Then
        Call GdipCreateBitmapFromScan0(Blur_UCWidth&, Blur_UCHeight&, 0&, PixelFormat32bppARGB, ByVal 0&, hImage2)
        Call GdipGetImageGraphicsContext(hImage2, hGraphics2)

        bp.ExpandEdge = 0
        bp.Radius = BlurRadius&
              
        Call GdipCreateEffect(&H633C80A4, &H482B1843, &H28BEF29E, &HD4FDC534, lEffect)
        Call GdipSetEffectParameters(lEffect, bp, Len(bp))
              
        rcSource.Width = Blur_UCWidth&
        rcSource.Height = Blur_UCHeight&
    
        Call GdipDrawImageFX(hGraphics2, hImage, rcSource, 0, lEffect, 0, UnitPixel)
        
        GdipCreateTexture hImage2, &H0, hBrush
        
        If (Zoom <> 1) Then
            Dim lZoom
            If (Zoom < 0) Then
                GdipSetTextureWrapMode hBrush, WrapModeClamp
                lZoom = Zoom * -1
            Else
                GdipSetTextureWrapMode hBrush, WrapModeTile
                lZoom = Zoom
            End If
            
            GdipScaleTextureTransform hBrush, lZoom, lZoom, MatrixOrderAppend
            GdipTranslateTextureTransform hBrush, ((Blur_UCWidth& * -lZoom) / 2) + (Blur_UCWidth& / 2), ((Blur_UCHeight& * -lZoom) / 2) + (Blur_UCHeight& / 2), MatrixOrderAppend
        End If
        
        GdipFillPath gdipGraphics, hBrush, hPath
        
        
        'Cleanup
        Call GdipDeleteBrush(hBrush)
        Call GdipDeleteGraphics(hGraphics2)
        Call GdipDisposeImage(hImage)
        Call GdipDisposeImage(hImage2)
        Call GdipDeleteEffect(lEffect)
    End If
    
End Sub

Public Sub BlurZoomCopyBackground()
    BitBlt Blur_hDCMemory, 0, 0, Blur_UCWidth&, Blur_UCHeight&, hdc&, 0, 0, vbSrcCopy
End Sub

'size in Px
Public Sub CreateBlurZoomBuffer(UCWidth&, UCHeight&)
Dim DC As Long
    DestroyBlurZoomBuffer
   
    If (UCWidth& <= 0) Or (UCHeight& <= 0) Then
        Debug.Print "Err sGdip.CreateBlurZoomBuffer UCH or UCW <= 0"
        Exit Sub
    End If
    'Debug.Print " >CreateBlurZoomBuffer() " & UCWidth& & "," & UCHeight&
 
    DC = GetDC(0)
    Blur_hDCMemory = CreateCompatibleDC(0)
    Blur_hBmp = CreateCompatibleBitmap(DC, UCWidth&, UCHeight&)
    Blur_UCWidth = UCWidth
    Blur_UCHeight = UCHeight
    ReleaseDC 0&, DC
    Blur_OldhBmp = SelectObject(Blur_hDCMemory, Blur_hBmp)
End Sub

Public Sub DestroyBlurZoomBuffer()
    'Debug.Print " >DestroyBlurZoomBuffer()"
    If Blur_OldhBmp Then DeleteObject SelectObject(Blur_hDCMemory, Blur_OldhBmp): Blur_OldhBmp = 0
    If Blur_hDCMemory Then DeleteDC Blur_hDCMemory: Blur_hDCMemory = 0
End Sub

'Create a Reactangle path (support round)
Private Sub pvCreateRectPathI(ByRef x1&, ByRef y1&, ByRef X2&, ByRef Y2&, ByRef nRoundSize&, ByRef Path&)
Dim diameter&

    If (Path& <> 0) Then GdipDeletePath Path
    GdipCreatePath FillModeWinding, Path
    
    If (nRoundSize) Then
        diameter& = nRoundSize * 2
        'Top
        GdipAddPathLineI Path, x1 + nRoundSize, y1, X2 - nRoundSize, y1
        'TopRight
        GdipAddPathArcI Path, X2 - diameter, y1, diameter, diameter, 270, 90
        'Right
        GdipAddPathLineI Path, X2, y1 + nRoundSize, X2, Y2 - nRoundSize
        'BottomRight
        GdipAddPathArcI Path, X2 - diameter, Y2 - diameter, diameter, diameter, 0, 90
        'Bottom
        GdipAddPathLineI Path, x1 + nRoundSize, Y2, X2 - nRoundSize, Y2
        'BottomLeft
        GdipAddPathArcI Path, x1, Y2 - diameter, diameter, diameter, 90, 90
        'Left
        GdipAddPathLineI Path, x1, y1 + nRoundSize, x1, Y2 - nRoundSize
        'TopLeft
        GdipAddPathArcI Path, x1, y1, diameter, diameter, 180, 90
    Else
        'Top:Right
        GdipAddPathLineI Path, x1, y1, X2, y1: GdipAddPathLineI Path, X2, y1, X2, Y2
        'Bottom:Left
        GdipAddPathLineI Path, X2, Y2, x1, Y2: GdipAddPathLineI Path, x1, Y2, x1, y1
    End If
    GdipClosePathFigure Path
End Sub








'--------------- TEST -------------------------------------------------------------------

Private Function iparseIsArrayEmpty(FarPointer As Long) As Long
  ' test to see if an array has been initialized
  CopyMemory iparseIsArrayEmpty, ByVal FarPointer, 4&
End Function

'by Leandro Ascierto
Private Function CreateStream(byteContent() As Byte, Optional byteOffset As Long = 0&) As stdole.IUnknown
    ' Purpose: Create an IStream-compatible IUnknown interface containing the
    ' passed byte aray. This IUnknown interface can be passed to GDI+ functions
    ' that expect an IStream interface -- neat hack
    On Error GoTo HandleError
    Dim o_lngLowerBound As Long
    Dim o_lngByteCount  As Long
    Dim o_hMem As Long
    Dim o_lpMem  As Long
     
    If iparseIsArrayEmpty(VarPtrArray(byteContent)) = 0& Then ' create a growing stream as needed
         Call CreateStreamOnHGlobal(0, 1, CreateStream)
    Else                                        ' create a fixed stream
         o_lngByteCount = UBound(byteContent) - byteOffset + 1
         o_hMem = GlobalAlloc(&H2&, o_lngByteCount)
         If o_hMem <> 0 Then
             o_lpMem = GlobalLock(o_hMem)
             If o_lpMem <> 0 Then
                 CopyMemory ByVal o_lpMem, byteContent(byteOffset), o_lngByteCount
                 Call GlobalUnlock(o_hMem)
                 Call CreateStreamOnHGlobal(o_hMem, 1, CreateStream)
             End If
         End If
     End If
   
HandleError:
End Function

Private Function StreamToImage(ByRef InStream() As Byte, ByRef hImage As Long) As Boolean
Dim IStream As IUnknown
  
    If iparseIsArrayEmpty(VarPtrArray(InStream)) = 0& Then Exit Function
    Set IStream = CreateStream(InStream())
   
    If Not IStream Is Nothing Then
 
        If GdipLoadImageFromStream(ObjPtr(IStream), hImage) = 0 Then
            StreamToImage = hImage <> 0
        End If
           
        Set IStream = Nothing
    End If
End Function

Private Function ImageToStream(ByVal hImage As Long, ByRef OutStream() As Byte, ByVal JPG_Quality As Long) As Boolean
Dim tEncoder    As GUID
Dim tParams     As EncoderParameters
Dim IStream    As IUnknown
   
    Erase OutStream
    If hImage = 0 Then Exit Function
    Set IStream = CreateStream(OutStream)
    If Not IStream Is Nothing Then
        CLSIDFromString StrPtr(ImageCodecJPG), tEncoder

        With tParams
            .Count = 1
            .Parameter(0).NumberOfValues = 1
            .Parameter(0).type = EncoderParameterValueTypeLong
            .Parameter(0).value = VarPtr(JPG_Quality)
            CLSIDFromString StrPtr(EncoderQuality), .Parameter(0).GUID
        End With

        If GdipSaveImageToStream(hImage, IStream, tEncoder, tParams) = 0& Then
            ImageToStream = ArrayFromStream(IStream, OutStream())
        End If
       
        Set IStream = Nothing
     End If
End Function

' Purpose: Return the array contained in an IUnknown interface
Private Function ArrayFromStream(Stream As IUnknown, arrayBytes() As Byte) As Boolean
Dim o_hMem As Long, o_lpMem As Long
Dim o_lngByteCount As Long
   
    If Not Stream Is Nothing Then
   
        If GetHGlobalFromStream(ByVal ObjPtr(Stream), o_hMem) = 0 Then
            o_lngByteCount = GlobalSize(o_hMem)
            If o_lngByteCount > 0 Then
                o_lpMem = GlobalLock(o_hMem)
                If o_lpMem <> 0 Then
                    ReDim arrayBytes(0 To o_lngByteCount - 1)
                    CopyMemory arrayBytes(0), ByVal o_lpMem, o_lngByteCount
                    GlobalUnlock o_hMem
                    ArrayFromStream = True
                End If
            End If
        End If

    End If
End Function

'=============================================================================================
'Load a GDI Image (Return a hImage)
'Accept a filename (relative and full path), StdPicture, Bytesarray, URL or pointer to a hImg,
' Stream or Icon pointer.
'optional OutByteArr to get the bytearray of the image (depending on imput may not return it)
'=============================================================================================
Public Function LoadImg(ByRef FileNameOrBytesOrPicOrhImg, Optional ByRef OutByteArr) As Long
On Error GoTo Err:
Dim img As Long, FileName$, tmpimg&
Dim b() As Byte, Strm As IUnknown
Dim auxl&, uName$
    
    Select Case VarType(FileNameOrBytesOrPicOrhImg)
    Case (vbArray Or vbByte)
        'Byte Array
        b = FileNameOrBytesOrPicOrhImg
        If (UBound(b) = 0) Then Exit Function
        OutByteArr = b
        'CreateStreamOnHGlobal VarPtr(b(0)), 0, Strm
        'GdipLoadImageFromStream ObjPtr(Strm), img
        
        'The hImage will be destroyed when the stream is reused to load another image
        'FIX: Create another Stream
        StreamToImage b, img
        
    Case vbString
        uName$ = UCase(FileNameOrBytesOrPicOrhImg)
        'Base64 detection when start with "DATA:"
        If (Left$(uName$, 5) = "DATA:") Then
            auxl = InStr(FileNameOrBytesOrPicOrhImg, ",")
            auxl = RangeL(auxl, 5, 100)
            OutByteArr = Base64Dec(Right$(FileNameOrBytesOrPicOrhImg, Len(FileNameOrBytesOrPicOrhImg) - auxl))
            img = LoadImg(OutByteArr)
        'URL
        ElseIf (Left$(uName$, 5) = "HTTP:") Or (Left$(uName$, 6) = "HTTPS:") Then
            OutByteArr = OpenURL(FileNameOrBytesOrPicOrhImg)
            img = LoadImg(OutByteArr)
            
        'Base64 detection when string is more than 250 chars and dont start with "DATA:"
        ElseIf (Len(FileNameOrBytesOrPicOrhImg) > 250) And Not (Mid(FileNameOrBytesOrPicOrhImg, 2, 1) = ":") Then
            'img = DecImgFromBase64(CStr(FileNameOrBytesOrPicOrhImg))
            OutByteArr = Base64Dec(CStr(FileNameOrBytesOrPicOrhImg))
            img = LoadImg(OutByteArr)
            
        'Asume string is a path
        Else
            
            'Detect if Path is relative or a fullpath <- check for drive letter
            If (Mid(FileNameOrBytesOrPicOrhImg, 2, 1) = ":") Then
                'fullpath (nothing to do)
                FileName$ = Trim(FileNameOrBytesOrPicOrhImg)
            ElseIf (Mid(FileNameOrBytesOrPicOrhImg, 2, 1) = ":") Then
            Else
                'Blank image?
                If (FileNameOrBytesOrPicOrhImg = "") Then Exit Function
                'relative -> add exe path
                FileName$ = AppPath & "\" & Trim(FileNameOrBytesOrPicOrhImg)
            End If
            OutByteArr = ReadBytesFromFile(FileName$)
            img = LoadImg(OutByteArr)
            
        End If
    
    Case vbLong
        Const OBJ_BITMAP As Long = 7
        
        If GetObjectType(FileNameOrBytesOrPicOrhImg) = OBJ_BITMAP Then
            GdipCreateBitmapFromHBITMAP FileNameOrBytesOrPicOrhImg, 0, img
        Else
            'Check if its a hImage (dont know how to check for valid hImage so try to load
            'icon first. If I try to get width property for an invalid hImage it crash)
            auxl& = GdipCreateBitmapFromHICON(FileNameOrBytesOrPicOrhImg, img)
            If (img = 0) Then GdipCloneImage FileNameOrBytesOrPicOrhImg, img
        End If
                
    Case vbDataObject
        'GdipLoadImageFromStream FileNameOrBytesOrPicOrhImg, img
        b = FileNameOrBytesOrPicOrhImg
        StreamToImage b, img
        ReDim OutByteArr(0)
        
    End Select

    If (img = 0) Then
        Debug.Print "Err: LoadImg: Cant load " & FileNameOrBytesOrPicOrhImg & " - " & Err.Description
        Exit Function
    End If
    
    LoadImg = img
    
    'DEBUG loaded image
    'GdipDrawImageRectI gdipGraphics, img, 10, 10, 42, 42

    Exit Function
Err:
    Debug.Print "LoadImg Err: " & Err.Description
End Function

Public Sub DestroyHImage(ByRef hImg&)
    If (hImg& = 0) Then Exit Sub
    GdipDisposeImage hImg&
    hImg& = 0
End Sub


Public Sub DrawImg(ByVal img As Long, Optional X& = 0, Optional Y& = 0, Optional X2& = -1, Optional Y2& = -1, Optional DrawScale! = 1)
Dim Width&, Height&

    If (DrawScale <> 1!) Then
        GdipScaleWorldTransform gdipGraphics, DrawScale, DrawScale, MatrixOrderPrepend
    End If

    If (X2 = -1) Then GdipGetImageWidth img, X2
    If (Y2 = -1) Then GdipGetImageHeight img, Y2
    
    'Call GdipSetSmoothingMode(gdipGraphics, smAntiAlias) ' 4=smAntiAlias
    
    GdipDrawImageRectI gdipGraphics, img, X, Y, X2, Y2
    
    If (DrawScale <> 1!) Then
        GdipResetWorldTransform gdipGraphics
    End If
    
End Sub

Public Sub DrawImgRotated(img As Long, AngleDeg!, Optional X& = 0, Optional Y& = 0, Optional X2& = -1, Optional Y2& = -1)
Dim Width&, Height&

    If (X2 = -1) Then GdipGetImageWidth img, X2
    If (Y2 = -1) Then GdipGetImageHeight img, Y2
    
    GdipRotateWorldTransform gdipGraphics, AngleDeg!, 0
    GdipTranslateWorldTransform gdipGraphics, X + (X2 / 2), Y + (Y2 / 2), 1
    Call GdipSetSmoothingMode(gdipGraphics, smAntiAlias) ' 4=smAntiAlias
    
    GdipDrawImageRectI gdipGraphics, img, -(X2 / 2), -(Y2 / 2), X2, Y2
    
    GdipResetWorldTransform gdipGraphics
    
End Sub

Public Sub DrawImgWithEffect(img As Long, Optional Alpha! = 1, Optional Effect As eSB_Img_Effect = 0, Optional Rotation! = 0, Optional ByVal X& = 0, Optional ByVal Y& = 0, Optional ByVal XWidth& = -1, Optional ByVal YHeight& = -1, Optional DrawScale! = 1, Optional bFlipX As Boolean, Optional bFlipY As Boolean)
Dim Width&, Height&, HalfW&, HalfH&
Dim ImgAttr&
Dim CM(0 To 24) As Single
'Dim clrMatrix(4, 4) As Single
Const SRCUNIT_PIXELS = 2

    Dim simgWidth!, simgHeight!
    GetImageDimension img, simgWidth, simgHeight!
    Width& = CLng(simgWidth): Height& = CLng(simgHeight!)
    
    If (XWidth = -1) Then XWidth = Width&
    If (YHeight = -1) Then YHeight = Height&

    If (DrawScale <> 1!) Then
        GdipScaleWorldTransform gdipGraphics, DrawScale, DrawScale, MatrixOrderPrepend
    End If
    
    If (bFlipX) Then
        X = X + XWidth
        XWidth = -XWidth
    End If
    If (bFlipY) Then
        Y = Y + YHeight
        YHeight = -YHeight
    End If
    
    

    'Apply rotation/scale from center
    If (Rotation <> 0) Or (DrawScale <> 1!) Then
        HalfW& = (XWidth / 2)
        HalfH& = (YHeight / 2)
        GdipRotateWorldTransform gdipGraphics, Rotation!, 0
        GdipTranslateWorldTransform gdipGraphics, X + HalfW&, Y + HalfH&, 1
        X = -HalfW&
        Y = -HalfH&
    End If
    
    Call GdipSetSmoothingMode(gdipGraphics, smAntiAlias) ' 4=smAntiAlias
    
    GdipCreateImageAttributes ImgAttr

    'Identity
    CM(0) = 1: CM(6) = 1: CM(12) = 1: 'CM(18) = 1:
    CM(24) = 1
    CM(18) = Alpha!

    'Setup the transform matrix
    Select Case Effect
    Case 0 ' None
        'CM(0) = 1: CM(6) = 1: CM(12) = 1: CM(18) = 1: CM(24) = 1
    Case 1 ' Greyscale
        CM(0) = 0.299: CM(1) = 0.299: CM(2) = 0.299
        CM(5) = 0.587: CM(6) = 0.587: CM(7) = 0.587
        CM(10) = 0.114: CM(11) = 0.114: CM(12) = 0.114
        
    Case 2 ' Greyscale Dark
        CM(0) = 0.2: CM(1) = 0.2: CM(2) = 0.2
        CM(5) = 0.387: CM(6) = 0.387: CM(7) = 0.387
        CM(10) = 0.114: CM(11) = 0.114: CM(12) = 0.114
        
    Case 3 ' Greyscale Light
        CM(0) = 0.4: CM(1) = 0.4: CM(2) = 0.4
        CM(5) = 0.587: CM(6) = 0.587: CM(7) = 0.587
        CM(10) = 0.414: CM(11) = 0.414: CM(12) = 0.414
        
    Case 4 ' Inverted
        CM(0) = -1: CM(6) = -1: CM(12) = -1
        
    Case 5 'BW 1
        CM(0) = 1.1: CM(1) = 1.1: CM(2) = 1.1
        CM(5) = 1.387: CM(6) = 1.387: CM(7) = 1.387
        CM(10) = 1.114: CM(11) = 1.114: CM(12) = 1.114
        CM(20) = -1: CM(21) = -1: CM(22) = -1
    
    Case 6 'BW 2
        CM(0) = 1.1: CM(1) = 1.1: CM(2) = 1.1
        CM(5) = 1.1: CM(6) = 1.1: CM(7) = 1.1
        CM(10) = 0.3: CM(11) = 0.3: CM(12) = 0.3
        CM(20) = 0.5: CM(21) = 0.5: CM(22) = 0.5
    
    Case 7 'BW 3
        CM(0) = 0.5: CM(1) = 0.5: CM(2) = 0.5
        CM(5) = 2.1: CM(6) = 2.1: CM(7) = 2.1
        CM(10) = 2.5: CM(11) = 2.5: CM(12) = 2.5
        CM(20) = -0.5: CM(21) = -0.5: CM(22) = -0.5
    
    Case 8 ' Darker
        CM(20) = -0.15: CM(21) = -0.15: CM(22) = -0.15
        
    Case 9 ' Lighter
        CM(20) = 0.15: CM(21) = 0.15: CM(22) = 0.15
    
    Case 10 ' show alpha channel
        CM(15) = 1: CM(16) = 1: CM(17) = 1: CM(18) = 1
        CM(23) = 1
        
    Case 11 ' eSB_IFX_GBR
        CM(0) = 0: CM(1) = 1: CM(2) = 0
        CM(5) = 0: CM(6) = 0: CM(7) = 1
        CM(10) = 1: CM(11) = 0: CM(12) = 0
        
    Case 12 ' EnhanceRed
        CM(0) = 1.25
        
    Case 13 ' EnhanceGreen
        CM(6) = 1.25
        
    Case 14 ' EnhanceBlue
        CM(12) = 1.25
    
    Case 15 ' TintRed
        CM(0) = 1: CM(1) = 0: CM(2) = 0
        CM(5) = 1: CM(6) = 0.5: CM(7) = 0
        CM(10) = 1: CM(11) = 0: CM(12) = 0.5
        
    Case 16 ' TintGreen
        CM(0) = 0.5: CM(1) = 1: CM(2) = 0
        CM(5) = 0: CM(6) = 1: CM(7) = 0
        CM(10) = 0: CM(11) = 1: CM(12) = 0.5
        
    Case 17 ' TintBlue
        CM(0) = 0.5: CM(1) = 0: CM(2) = 1
        CM(5) = 0: CM(6) = 0.5: CM(7) = 1
        CM(10) = 0: CM(11) = 0: CM(12) = 1
    
    Case 20 To 30 ' ForceAlpha (10 to 90%)
        CM(18) = (CSng(Effect) - 20) / 10 ' 0.8 Alpha transform
    End Select

    GdipSetImageAttributesColorMatrix ImgAttr, 0&, 1&, CM(0), CM(0), 0&
    GdipDrawImageRectRectI gdipGraphics, img, X, Y, XWidth, YHeight, 0, 0, Width&, Height&, 2, ImgAttr
    
    If (Rotation <> 0) Or (DrawScale <> 1!) Then
        GdipResetWorldTransform gdipGraphics
    End If
    
    If ImgAttr Then GdipDisposeImageAttributes ImgAttr
    
End Sub

'LoadStdPictureEx is a better version
Public Function pvLoadPicture(hBitmap As Long) As StdPicture
    Dim sngWidth        As Single
    Dim sngHeight       As Single
    Dim hMemDC          As Long
    Dim hDIB            As Long
    Dim hPrevDib        As Long
    Dim hGraphics       As Long
    Dim uInfo           As IconInfo
    Dim hIcon           As Long
    Dim uDesc           As PICTDESC
    Dim aGUID(0 To 3)   As Long
    
    On Error GoTo EH
    If GdipGetImageDimension(hBitmap, sngWidth, sngHeight) <> 0 Then
        GoTo QH
    End If
    hMemDC = CreateCompatibleDC(0)
    If hMemDC = 0 Then
        GoTo QH
    End If
    If Not pvCreateDib(hMemDC, sngWidth, sngHeight, hDIB) Then
        GoTo QH
    End If
    hPrevDib = SelectObject(hMemDC, hDIB)
    If GdipCreateFromHDC(hMemDC, hGraphics) <> 0 Then
        GoTo QH
    End If
    If GdipDrawImageRectRect(hGraphics, hBitmap, 0, 0, sngWidth, sngHeight, 0, 0, sngWidth, sngHeight) <> 0 Then
        GoTo QH
    End If
    Call SelectObject(hMemDC, hPrevDib)
    hPrevDib = 0
    With uInfo
        .fIcon = 1
        .hbmColor = hDIB
        .hbmMask = CreateBitmap(sngWidth, sngHeight, 1, 1, ByVal 0)
    End With
    hIcon = CreateIconIndirect(uInfo)
    With uDesc
        .lSize = Len(uDesc)
        .lType = vbPicTypeIcon
        .hBmp = hIcon
    End With
    aGUID(0) = &H7BF80980
    aGUID(1) = &H101ABF32
    aGUID(2) = &HAA00BB8B
    aGUID(3) = &HAB0C3000
    If OleCreatePictureIndirect(uDesc, aGUID(0), 1, pvLoadPicture) <> 0 Then
        GoTo QH
    End If
    hIcon = 0
QH:
    If hBitmap <> 0 Then
        Call GdipDisposeImage(hBitmap)
        hBitmap = 0
    End If
    If hMemDC <> 0 Then
        If hPrevDib <> 0 Then
            Call SelectObject(hMemDC, hPrevDib)
        End If
        Call DeleteDC(hMemDC)
        hMemDC = 0
    End If
    If hDIB <> 0 Then
        Call DeleteObject(hDIB)
        hDIB = 0
    End If
    If hGraphics <> 0 Then
        Call GdipDeleteGraphics(hGraphics)
        hGraphics = 0
    End If
    If hIcon <> 0 Then
        Call DestroyIcon(hIcon)
        hIcon = 0
    End If
    If uInfo.hbmMask <> 0 Then
        Call DeleteObject(uInfo.hbmMask)
        uInfo.hbmMask = 0
    End If
    Exit Function
EH:
    Debug.Print "pvLoadPicture Err: " & Err.Description
    Resume QH
End Function

Private Function pvCreateDib(ByVal hMemDC As Long, ByVal lWidth As Long, ByVal lHeight As Long, hDIB As Long) As Boolean
'Dim uHdr            As BITMAPINFOHEADER
Dim uHdr            As BITMAPINFO
Dim lpBits          As Long
    
    On Error GoTo EH
    With uHdr.bmiHeader
        .biSize = Len(uHdr)
        .biPlanes = 1
        .biBitCount = 32
        .biWidth = lWidth
        .biHeight = -lHeight
        .biSizeImage = 4 * lWidth * lHeight
    End With
    hDIB = CreateDIBSection(hMemDC, uHdr, DIB_RGB_COLORS, lpBits, 0, 0)
    If hDIB = 0 Then
        GoTo QH
    End If
    '--- success
    pvCreateDib = True
QH:
    Exit Function
EH:
    Debug.Print "pvCreateDib Err: " & Err.Description
    Resume QH
End Function

'Convert hex character values to unicode chars
Private Function CharvalToUnicode(sCharval$) As String
Dim v As Variant, i&, w$, Char$, b1$, b2$
    If (Len(sCharval$) < 4) Then sCharval$ = Right("0000" & sCharval$, 4)
    
    'Parse the 4 values of hex unicode value
    For i = 1 To Len(sCharval$)
        Char$ = Mid$(sCharval$, i, 1)
        'if a space is found add it
        If (Char$ = " ") Then
            CharvalToUnicode = CharvalToUnicode & Chr(32) & Chr(0)
        ElseIf (Char$ = "/") Then
            'Add unicode enter
            CharvalToUnicode = CharvalToUnicode & Chr(13) & Chr(0) & Chr(10) & Chr(0)
            'Skip next char
            i = i + 1
        Else
            w$ = w$ & Char$
            If (Len(w$) = 4) Then
                'Reverse the bytes order
                b1$ = "&H" & Right(w$, 2)
                b2$ = "&H" & Left(w$, 2)
                CharvalToUnicode = CharvalToUnicode & Chr(b1$) & Chr(b2$)
                w$ = ""
            End If
        End If
    Next i
    
End Function

Public Function GetImageDimension(ByRef hImage As Long, nWidth As Single, nHeight As Single)
    GetImageDimension = GdipGetImageDimension(hImage, nWidth, nHeight)
End Function

Public Sub GetHIconFromImage(ByRef img&, ByRef hNewGraphics&)
    GdipCreateHICONFromBitmap img&, hNewGraphics&
End Sub

Public Sub DestroyHIcon(ByRef hIcon As Long)
    If hIcon Then DestroyIcon hIcon
    hIcon = 0
End Sub

Public Sub DestroyHCursor(ByRef hCursor As Long)
  If hCursor Then DestroyCursor hCursor
  hCursor = 0
End Sub

Public Function GetHCursorFromImage(img&, Optional ByVal HSpotX As Long, Optional ByVal HSpotY As Long) As Long
Dim hIcon As Long, IconInfo(0 To 4) As Long
    GdipCreateHICONFromBitmap img&, hIcon
    If hIcon Then GetIconInfo hIcon, IconInfo(0)
    IconInfo(0) = 0: IconInfo(1) = HSpotX: IconInfo(2) = HSpotY
    GetHCursorFromImage = CreateIconIndirect(IconInfo(0))
    If IconInfo(3) Then DeleteObject IconInfo(3)
    If IconInfo(4) Then DeleteObject IconInfo(4)
    DestroyIcon hIcon
End Function

'To load PNG into StdPicture simulating transparency using a backcolor
'Example: Set Image1.Picture = .LoadStdPictureEx("img\x.png", , , vbRed)
'It also support a StdPicture as parameter
Public Function LoadStdPictureEx(FileNameOrBytesOrImg, Optional Width As Long = -1, Optional Height As Long = -1, Optional ByVal BackColor As Long = vbWhite, Optional RetainRatio As Boolean = False) As IPicture
Dim FileName$, phDC&, hBitmap&, img&, bDontDispose As Boolean
    
    If (BackColor < 0) Then BackColor = GetSysColor(BackColor - &H80000000)

    ' Load the image
    If (VarType(FileNameOrBytesOrImg) = vbLong) Then
        'hImage passed
        img = FileNameOrBytesOrImg
        bDontDispose = True
    Else
        img = LoadImg(FileNameOrBytesOrImg)

        'If GdipLoadImageFromFile(StrPtr(PicFile), Img) <> 0 Then
        If (img = 0) Then
            Err.Raise 999, "GDI+ Module", "Error loading picture: " & Err.Description

            Exit Function

        End If
    End If
    
    ' Calculate picture's width and height if not specified
    If Width = -1 Or Height = -1 Then
        GdipGetImageWidth img, Width
        GdipGetImageHeight img, Height
    End If
    
    Dim hBrush&, oldBrush&

    ' Create a memory DC and select a bitmap into it, fill it in with the backcolor
    phDC = CreateCompatibleDC(ByVal 0&)
    hBitmap = CreateBitmap(Width, Height, GetDeviceCaps(phDC, 14), GetDeviceCaps(phDC, 12), ByVal 0&) '14=planes,12=BITSPIXEL
    hBitmap = SelectObject(phDC, hBitmap)
    hBrush = CreateSolidBrush(BackColor)
    oldBrush = SelectObject(phDC, hBrush)
    PatBlt phDC, 0, 0, Width, Height, &HF00021 'PATCOPY = &HF00021     ' (DWORD) dest = pattern
    Call SelectObject(phDC, oldBrush)
    DeleteObject hBrush

    ' Resize and paint the picture
    pvgdipResize img, phDC, Width, Height, RetainRatio
    If (bDontDispose = False) Then GdipDisposeImage img
    
    ' Get the bitmap back
    pvGetBitmap phDC, hBitmap
    'SelectObject phDC, hBitmap
    'DeleteDC phDC

    ' Create the picture
    Set LoadStdPictureEx = pvCreatePicture(hBitmap)
     
End Function

'Replaces the old bitmap of the hDC, Returns the bitmap and Deletes the hDC
'Called from LoadStdPictureEx (need to be in a separated sub)
Private Sub pvGetBitmap(phDC As Long, hBitmap As Long)
    hBitmap = SelectObject(phDC, hBitmap)
    DeleteDC phDC
End Sub

' Creates a Picture Object from a handle to a bitmap
'Called from LoadStdPictureEx
Private Function pvCreatePicture(hBitmap As Long) As IPicture

    Dim IID_IDispatch(0 To 3) As Long
    'Dim IID_IDispatch As Guid
    Dim Pic                   As PICTDESC
    Dim IPic                  As IPicture
    ' Fill in OLE IDispatch Interface ID
    IID_IDispatch(0) = &H20400: IID_IDispatch(2) = &HC0: IID_IDispatch(3) = &H46000000
        
    ' Fill Pic with necessary parts
    Pic.lSize = Len(Pic)        ' Length of structure
    Pic.lType = vbPicTypeBitmap  ' Type of Picture (bitmap)
    Pic.hBmp = hBitmap         ' Handle to bitmap

    ' Create the picture
    OleCreatePictureIndirect Pic, IID_IDispatch(0), True, IPic
    Set pvCreatePicture = IPic
End Function

' Resize the picture using GDI plus
'Called from LoadStdPictureEx
Private Sub pvgdipResize(img As Long, _
                         hdc As Long, _
                         Width As Long, _
                         Height As Long, _
                         Optional RetainRatio As Boolean = False)

    Dim graphics   As Long      ' Graphics Object Pointer
    Dim OrWidth    As Long      ' Original Image Width
    Dim OrHeight   As Long      ' Original Image Height
    Dim OrRatio    As Double    ' Original Image Ratio
    Dim DesRatio   As Double    ' Destination rect Ratio
    Dim DestX      As Long      ' Destination image X
    Dim DestY      As Long      ' Destination image Y
    Dim DestWidth  As Long      ' Destination image Width
    Dim DestHeight As Long      ' Destination image Height
    
    GdipCreateFromHDC hdc, graphics
    GdipSetInterpolationMode graphics, InterpolationModeHighQualityBicubic
    
    If RetainRatio Then
        GdipGetImageWidth img, OrWidth
        GdipGetImageHeight img, OrHeight
        
        OrRatio = OrWidth / OrHeight
        DesRatio = Width / Height
        
        ' Calculate destination coordinates
        DestWidth = IIf(DesRatio < OrRatio, Width, Height * OrRatio)
        DestHeight = IIf(DesRatio < OrRatio, Width / OrRatio, Height)
        '        DestX = (Width - DestWidth) / 2
        '        DestY = (Height - DestHeight) / 2

        DestX = 0
        DestY = 0

        GdipDrawImageRectRectI graphics, img, DestX, DestY, DestWidth, DestHeight, 0, 0, OrWidth, OrHeight, UnitPixel, 0, 0, 0
    Else
        GdipDrawImageRectI graphics, img, 0, 0, Width, Height
    End If

    GdipDeleteGraphics graphics
End Sub

''Equivalent to GdipLoadStdPictureFilename+GdipLoadStdPictureArray
'Public Function GdipLoadStdPictureFileArray(sFileNameOrBytes) As StdPicture
'On Error GoTo Err:
'Dim Img As Long
'Dim B() As Byte, Filename$
'    If VarType(sFileNameOrBytes) = vbString Then
'        'Detect if Path is relative or a fullpath <- check for drive letter
'        If (Mid(sFileNameOrBytes, 2, 1) = ":") Then
'            'fullpath (nothing to do)
'            Filename$ = sFileNameOrBytes
'        Else
'            'relative -> add exe path
'            Filename$ = App.Path & "\" & sFileNameOrBytes
'        End If
'        B = ReadBytesFromFile(Filename$)
'    Else
'        B = sFileNameOrBytes
'    End If
'    Set GdipLoadStdPictureFileArray = GdipLoadStdPictureArray(B)
'    Exit Function
'Err:
'    Debug.Print "GdipLoadStdPictureFileArray Err: " & Err.Description
'End Function
'
'Public Function GdipLoadStdPictureFilename(sFIleName As String) As StdPicture
'    Const FUNC_NAME     As String = "GdipLoadPicture"
'    Dim hBitmap         As Long
'
'    On Error GoTo EH
'    If GdipLoadImageFromFile(StrPtr(sFIleName), hBitmap) <> 0 Then
'        GoTo QH
'    End If
'    Set GdipLoadStdPictureFilename = pvLoadPicture(hBitmap)
'QH:
'    Exit Function
'EH:
'    Debug.Print "GdipLoadStdPictureFilename Err: " & Err.Description
'    Resume QH
'End Function
'
'Public Function GdipLoadStdPictureArray(baBuffer() As Byte) As StdPicture
'Dim pStream As stdole.IUnknown
'Dim hBitmap As Long
'
'    On Error GoTo EH
'    Set pStream = SHCreateMemStream(baBuffer(LBound(baBuffer)), UBound(baBuffer) - LBound(baBuffer) + 1)
'    If pStream Is Nothing Then
'        GoTo QH
'    End If
'    If GdipLoadImageFromStream(ObjPtr(pStream), hBitmap) <> 0 Then
'        GoTo QH
'    End If
'
'    Set GdipLoadStdPictureArray = pvLoadPicture(hBitmap)
'QH:
'    Exit Function
'EH:
'    Debug.Print "GdipLoadStdPictureArray Err: " & Err.Description
'    Resume QH
'End Function

Public Function EncFileToBase64(FullPath$, Optional ForCode As Boolean) As String

    On Error GoTo Err:

    Dim b() As Byte

    b = ReadBytesFromFile(FullPath$)

    If Not (ForCode) Then
        EncFileToBase64 = Base64Enc(b)
    Else

        'Return vbcode with image inside a variable
        Dim X$, aux$, b64$, i&, iStart&, iMax&

        b64$ = Base64Enc(b)
        iMax& = Len(b64)
        iStart& = 1

        Do
            aux$ = Mid$(b64, iStart, 914)

            If (iStart = 1) Then
                X$ = "s$ =""" & aux$ & """" & vbCrLf
            Else
                X$ = X$ & "s$ = s$ & """ & aux$ & """" & vbCrLf
            End If

            iStart& = iStart + 914
        Loop Until iStart > iMax

        EncFileToBase64 = X$
    End If
        
    'Debug.Print EncFileToBase64
    Exit Function

Err:
    Debug.Print "EncFileToBase64 Err: " & Err.Description
End Function

'UNTESTED
Public Function DecStdPictureFromBase64(s$) As StdPicture

    On Error GoTo Err:

    Set DecStdPictureFromBase64 = LoadStdPictureEx(Base64Dec(s$))

    Exit Function

Err:
    Debug.Print "DecStdPictureFromBase64 Err: " & Err.Description
End Function

Public Function DecImgFromBase64(s$) As Long

    On Error GoTo Err:

    DecImgFromBase64 = LoadImg(Base64Dec(s$))

    Exit Function

Err:
    Debug.Print "DecImgFromBase64 Err: " & Err.Description
End Function

'Public Function SaveImageToPngByteArray(hImg) As Byte()
'  SaveImageToPngByteArray = "" 'return an initialized, byte empty (0 to -1) ByteArray in case of an error
'  Dim Strm As stdole.IUnknown, SizeLL(0 To 1) As Long, B() As Byte
'  CreateStreamOnHGlobal 0, 1, Strm
'  If Strm Is Nothing Then Exit Function
'
'  GdipSaveImageToStream mImages(Key), ObjPtr(Strm), mPngID(0), ByVal 0&
'  IStream_Size ObjPtr(Strm), SizeLL(0)
'  If SizeLL(0) > 0 Then ReDim B(0 To SizeLL(0) - 1) Else Exit Function
'
'  IStream_Reset ObjPtr(Strm)
'  IStream_Read ObjPtr(Strm), B(0), SizeLL(0)
'  SaveImageToPngByteArray = B
'End Function

'**** two pairs of Codec-Functions (for Base64 and RLE), mainly to support easy decoding of Image-Resources from a Base64-String-Const)
'Copied from cCache class by Olaf Schmidt
Public Function Base64Dec(sText) As Byte()

    Dim E As Object

    Set E = CreateObject("MSXML2.DOMDocument").CreateElement("E")
    E.DataType = "bin.base64": E.Text = sText
    Base64Dec = E.NodeTypedValue
End Function

Public Function Base64Enc(Bytes) As String

    Dim E As Object

    Set E = CreateObject("MSXML2.DOMDocument").CreateElement("E")
    E.DataType = "bin.base64": E.NodeTypedValue = Bytes
    Base64Enc = Replace(Replace(E.Text, vbLf, ""), vbCr, "")
End Function

Public Function RLEEnc(b() As Byte) As Byte()
    ReDim E(0 To UBound(b) * 2 + 1) As Byte 'twice the input-size

    Dim i As Long, J As Long, k As Long, n As Long

    For i = 0 To UBound(b)
        E(k) = b(i) \ 16: E(k + 1) = b(i) And 15: k = k + 2
    Next
  
    For i = 0 To UBound(E)
        For k = i + 1 To UBound(E)

            If n = 15 Or E(i) <> E(k) Then Exit For Else n = n + 1
        Next

        E(J) = n + 16 * E(i): J = J + 1: i = i + n: n = 0
    Next

    ReDim Preserve E(0 To J - 1): RLEEnc = E 'return the result
End Function

Public Function RLEDec(b() As Byte) As Byte()

    Dim i As Long, J As Long, k As Long, sz As Long

    For i = 0 To UBound(b): sz = sz + (b(i) And 15) + 1: Next
    ReDim d(0 To sz - 1) As Byte

    For i = 0 To UBound(b)
        For k = 0 To b(i) And 15: d(J) = b(i) \ 16: J = J + 1: Next
    Next
  
    For i = 0 To sz \ 2 - 1
        d(i) = d(i + i) * 16 + d(i + i + 1)
    Next

    ReDim Preserve d(0 To i - 1): RLEDec = d 'return the result
End Function

Public Function ReadBytesFromFile(ByVal FileName As String) As Byte()

    On Error GoTo Err:

    'Detect if Path is relative or a fullpath <- check for drive letter
    FileName$ = Trim(FileName)
    
    If (Mid(FileName, 2, 1) <> ":") Then FileName = AppPath & "\" & Trim(FileName)

    With CreateObject("ADODB.Stream")
        .Open
        .type = 1 'adTypeBinary
        .LoadFromFile FileName
        ReadBytesFromFile = .Read
        .Close
    End With

    Exit Function

Err:
    Debug.Print "ReadBytesFromFile Err: " & Err.Description
End Function

Public Sub WriteBytesToFile(ByVal FileName As String, b() As Byte)

    With CreateObject("ADODB.Stream")
        .Open
        .type = 1 'adTypeBinary
        .Write b
        .SaveToFile FileName, 2 'Create+Overwrite
        .Close
    End With

End Sub

Private Function bFileExists(FileName As String) As Boolean

    Dim TempAttr As Integer

    On Error GoTo ExitFileExist 'any errors show that the file doesnt exist, so goto this label

    TempAttr = GetAttr(FileName) 'get the attributes of the files
    bFileExists = ((TempAttr And vbDirectory) = 0) 'check if its a directory and not a file

ExitFileExist:

    On Error GoTo 0 'clear all errors

End Function

'================================================================
'Force system to repaint the window
'Optionally can block another window handle
'================================================================
'If BlockParent is true third parameter is ignored
Public Sub ForceUpdateWindow(lHwnd&, _
                             Optional BlockParent As Boolean, _
                             Optional LockWinHwnd As Long)

    If (BlockParent) Then LockWinHwnd = GetParent(lHwnd&)
    If (LockWinHwnd <> 0) Then LockWindowUpdate LockWinHwnd
    InvalidateRect lHwnd, 0&, 1&

    'UpdateWindow lHwnd
    If (LockWinHwnd <> 0) Then LockWindowUpdate 0
End Sub

'--------32BPP-----------
'F=form
Public Sub MakeForm32BPPTransparent(f As Object)

    Dim oldScalemode&, w&, h&

    oldScalemode& = f.ScaleMode
    f.ScaleMode = 3
    w = f.ScaleWidth:    h = f.ScaleHeight
    f.ScaleMode = oldScalemode
    Call MakeObj32BPPTransparent(f.hWnd, w, h)
End Sub

Public Sub MakeObj32BPPTransparent(lHwnd&, WidthPX&, HeightPX&)

    Dim curWinLong As Long

    curWinLong = GetWindowLong(lHwnd&, GWL_EXSTYLE)
    SetWindowLong lHwnd&, GWL_EXSTYLE, curWinLong Or WS_EX_LAYERED

    'Needed for ReleaseGraphics32BPPTransparent
    tmp32bppWinSize.X = WidthPX&:  tmp32bppWinSize.Y = HeightPX&

    With tempBI.bmiHeader
        .biSize = Len(tempBI.bmiHeader)
        .biBitCount = 32
        .biHeight = HeightPX&
        .biWidth = WidthPX&
        .biPlanes = 1
        .biSizeImage = .biWidth * .biHeight * (.biBitCount / 8)
    End With

    With blendFunc32bpp
        .AlphaFormat = AC_SRC_ALPHA
        .BlendFlags = 0
        .BlendOp = AC_SRC_OVER
        .SourceConstantAlpha = 255
    End With

End Sub

Public Sub CreateGraphics32BPPTransparent(lHDC&, _
                                          Optional GFXQuality As eGdip_GlobalQualityGFX = HA_Highest_Aliasing, _
                                          Optional TXTQuality As eGdip_GlobalQualityTXT = Cleartype)
    hdc = CreateCompatibleDC(lHDC&)

    If gdipStatus <> Ok Then
        Err.Raise &H80044021, TypeName(Me), "CreateGraphics32BPPTransparent error " & CStr(gdipStatus)

        Exit Sub

    End If
    
    mainBitmap = CreateDIBSection(hdc, tempBI, DIB_RGB_COLORS, ByVal 0, 0, 0)
    oldBitmap = SelectObject(hdc, mainBitmap)
    Call GdipCreateFromHDC(hdc, gdipGraphics)
    SetGlobalQuality GFXQuality, TXTQuality
End Sub

Public Sub ReleaseGraphics32BPPTransparent(lHwnd&, lHDC&)

    Dim lcHwnd&

    Dim srcPoint As POINTL
    
    If gdipGraphics <> 0 Then gdipStatus = GdipDeleteGraphics(gdipGraphics)
    If gdipFont <> 0 Then GdipDeleteFont (gdipFont)
    
    'Now graphics will be shown
    srcPoint.X = 0: srcPoint.Y = 0
    Call UpdateLayeredWindow(lHwnd&, lHDC&, ByVal 0&, tmp32bppWinSize, hdc, srcPoint, 0, blendFunc32bpp, ULW_ALPHA)

    'cleaning
    SelectObject hdc, oldBitmap
    DeleteObject mainBitmap
    DeleteObject oldBitmap
    DeleteDC hdc
    
End Sub

'============================================
'Get cursor icon from System
'============================================
Public Function GetSystemHandCursor() As Picture

    Dim Pic As PICTDESC, IPic As IPicture, GUID(0 To 3) As Long

    Dim hCur&

    hCur = LoadCursor(ByVal 0&, 32649) 'IDC_HAND
    GUID(0) = &H7BF80980
    GUID(1) = &H101ABF32
    GUID(2) = &HAA00BB8B
    GUID(3) = &HAB0C3000

    With Pic
        .lSize = Len(Pic)
        .lType = vbPicTypeIcon
        .hBmp = hCur
        .hpal = 0
    End With

    Call OleCreatePictureIndirect(Pic, GUID(0), 1, IPic)
    Set GetSystemHandCursor = IPic

    If hCur Then DestroyCursor hCur: hCur = 0
End Function

'By Leandro Ascierto
Public Property Get ScreenDPI() As Single

    Dim hdc As Long: hdc = GetDC(0)

    ScreenDPI = GetDeviceCaps(hdc, 118) / (Screen.Width / Screen.TwipsPerPixelX)
    ReleaseDC 0, hdc
End Property

'Untested
'vbFrm=Form
'vbPicBox = PictureBox
Public Sub MaskFormFromPicture(vbFrm As Object, _
                               vbPicBox As Object, _
                               Optional TransColor As Long)

    Dim RetR     As Long

    Dim RgnFinal As Long

    Dim RgnTmp   As Long

    Dim hHeight  As Long

    Dim wWidth   As Long

    Dim Col      As Long

    Dim Start    As Long

    Dim RowR     As Long

    vbPicBox.AutoSize = True
    vbPicBox.AutoRedraw = True

    With vbFrm
        .Height = vbPicBox.Height
        .Width = vbPicBox.Width
    End With

    'If no transparent color in param, take the top,left pixel color
    If TransColor < 1 Then
        TransColor = GetPixel(vbPicBox.hdc, 0, 0)
    End If

    hHeight = vbPicBox.Height / Screen.TwipsPerPixelY
    wWidth = vbPicBox.Width / Screen.TwipsPerPixelX

    RgnFinal = CreateRectRgn(0, 0, 0, 0)

    For RowR = 0 To hHeight - 1
        Col = 0

        Do While Col < wWidth
            Do While Col < wWidth And GetPixel(vbPicBox.hdc, Col, RowR) = TransColor
                Col = Col + 1
            Loop

            If Col < wWidth Then
                Start = Col

                Do While Col < wWidth And GetPixel(vbPicBox.hdc, Col, RowR) <> TransColor
                    Col = Col + 1
                Loop

                If Col > wWidth Then Col = wWidth

                RgnTmp = CreateRectRgn(Start, RowR, Col, RowR + 1)
                RetR = CombineRgn(RgnFinal, RgnFinal, RgnTmp, RGN_OR)
                DeleteObject (RgnTmp)

            End If

        Loop

    Next RowR

    RetR = SetWindowRgn(vbFrm.hWnd, RgnFinal, True)

End Sub

'
'    ;create buffered graphics frame set for smoother gfx object movements
'    $g_hGfx = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
'    $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGfx) ;create a Bitmap object based on a graphics object
'    $g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap) ;get the graphics context of the image / bitmap to draw on image / bitmap
'    _GDIPlus_GraphicsSetSmoothingMode($g_hGfxCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;sets the graphics object rendering quality (antialiasing)
'
'_GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor)
'_GDIPlus_GraphicsDrawImageRect($g_hGfx, $g_hBitmap, 0, 0, $iWidth, $iHeight) ;copy drawn bitmap to GUI
