home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / LaVolpe_Wo2107533262008.psc / clsWApath2.cls < prev   
Text File  |  2008-03-26  |  7KB  |  103 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsWApath"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. ' CLASS PURPOSE & GOALS
  17. ' -------------------------------
  18. ' 1. Wrap many common GDI+ path-related methods/routines
  19. ' 2. Handle complicated calculations & path-related matrix operations
  20. ' 3. Provide patches/workarounds for GDI+ path-related buggy code (warping, XOR drawing)
  21. ' 4. Provide flexible rendering routines & clone routines
  22. ' 5. Re-usable and expandable
  23.  
  24. ' IMPORTANT:  ARRAY POINTER USAGE
  25. ' --------------------------------
  26. ' Since this is a class and passing UDTs to it isn't allowed unless the UDTs are delcared public in a bas module.
  27. ' Some of the functions ask for array pointers. This has some benefits and only one drawback.
  28. ' The benfits are that you can use various storage items: Singles(), POINTF(), Bytes()
  29.  
  30. ' First, GDI+ uses POINTF structures quite often. This is simply an X,Y structure where X,Y are Singles & not Longs.
  31. ' Since the structure are Singles, you can either declare and use an array of POINTF structures in your project or
  32. ' use an array of Singles instead.  Always declare your arrays like the following:
  33. '       -- array of Singles: Dim mySingleArray(0 To 1, 0 To numberPoints-1) << 0 & 1 are X,Y coords respectively
  34. '       -- array of POINTF:  Dim myPOINTFarray(0 To numberPoints-1)
  35. ' Now when you need to pass pointers to the class, simply pass it using VB's VarPtr function:
  36. '       -- array of Singles:  VarPtr(mySingleArray(0, 0))
  37. '       -- array of POINTF:   VarPtr(myPOINTFarray(0))
  38. ' The drawback, crashes if you pass invalid pointers or do not size your array appropriately
  39. ' All functions that expect pointers have a PTR suffix in their function name.
  40. ' ALWAYS ENSURE THE ARRAY IS SIZED BEFORE ATTEMPTING TO PASS ARRAY POINTERS
  41.  
  42. ' ABOUT RENDERING, SCALING, OFFSETS
  43. ' ---------------------------------
  44. ' The path is never scaled, rotated or moved/repositioned once it is created.
  45. ' The class tracks the scale desired, angle desired, position desired, etc.
  46. ' When rendering occurs, a matrix is created to be used to place the path
  47. ' using set Angle, Scale, Offsets and then rendered to the DC via the matrix.
  48. ' This actually has several benefites and one or two drawbacks.
  49.  
  50. ' The benefits? Original path is never altered, this promotes better quality
  51. '   renderings. Since path is never physically modified, gradient/path brushes
  52. '   do not need to be destroyed/modifiied/recreated when a path is resized or moved.
  53. '   Rendering speed is improved in many scenarios, but not all
  54. '   Paths can be cloned "as rendered" via the Clone function
  55.  
  56. ' The drawbacks? Only major one I can think of :: hit testing a path on a DC if the project
  57. '   requires the ability to see if mouse is over a path. Since the path handle in this
  58. '   class is not the same dimensions/rotation as the rendered path, hit testing will fail.
  59. '   To resolve this, recommend creating a second class and calling this class' Clone
  60. '   method to get the path in rendered form.  When/If the rendered path changes scale,
  61. '   rotation or position, then replace the path with another call to the Clone method.
  62. '   -- Another drawback is that repainting via a matrix is slower than if the path
  63. '      was created at specific angle/size/position. However, this drawback only occurs
  64. '      when a DC's AutoRedraw=False otherwise, rendering generally only occurs when
  65. '      path properties change which is less common overall. Animating via matrix is faster
  66. '      overall than continually recreating a path to match the animated position/scale/rotation.
  67. ' -------------------------------------------------------------------------------------
  68.  
  69. ' ---=====| NON-GDI+ APIS |====---
  70.  
  71. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  72. ' following used for XOR rendering of path
  73. Private Declare Function CreatePen Lib "gdi32.dll" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
  74. Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hDC As Long, ByVal hObject As Long) As Long
  75. Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
  76. Private Declare Function LineTo Lib "gdi32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long) As Long
  77. Private Declare Function MoveToEx Lib "gdi32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByRef lpPoint As Any) As Long
  78. Private Declare Function PolyBezierTo Lib "gdi32.dll" (ByVal hDC As Long, ByRef lppt As Any, ByVal cCount As Long) As Long
  79. Private Declare Function SetROP2 Lib "gdi32.dll" (ByVal hDC As Long, ByVal nDrawMode As Long) As Long
  80. ' following used to saving path as an image
  81. Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpszProgID As Long, pCLSID As Any) As Long
  82. Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hWnd As Long, ByVal hDC As Long) As Long
  83. Private Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Long) As Long
  84. Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long
  85. Private Declare Function InflateRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  86. Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
  87. Private Declare Function CreateDIBSection Lib "gdi32.dll" (ByVal hDC As Long, ByRef pBitmapInfo As BITMAPINFO, ByVal un As Long, ByRef lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  88. Private Declare Function lstrlenW Lib "kernel32" (ByVal psString As Any) As Long
  89. Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hDC As Long) As Long
  90. Private Declare Function FillRect Lib "user32.dll" (ByVal hDC As Long, ByRef lpRect As RECT, ByVal hBrush As Long) As Long
  91. Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As Long
  92. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  93. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  94. Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
  95. Private Declare Function GetHGlobalFromStream Lib "ole32" (ByVal ppstm As Long, hGlobal As Long) As Long
  96. Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
  97. Private Declare Function OffsetRect Lib "user32.dll" (ByRef lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
  98. Private Declare Function UnionRect Lib "user32.dll" (ByRef lpDestRect As RECT, ByRef lpSrc1Rect As RECT, ByRef lpSrc2Rect As RECT) As Long
  99.  
  100. ' ---=====| GDI+ TEXT RELEATED APIS |====---
  101. Private Declare Function GdipCreateFontFamilyFromName Lib "gdiplus" (ByVal name As Long, ByVal fontCollection As Long, fontFamily As Long) As Long
  102. Private Declare Function GdipDeleteFontFamily Lib "gdiplus" (ByVal fontFamily As Long) As Long
  103. Private Declare Function GdipAddur ao