name22

GDI+ Spotlight

Dec 9th, 2012
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WindowsConstants.au3>
  2. #include <GUIConstants.au3>
  3. #include <GDIPlus.au3>
  4. #include <WinAPI.au3>
  5.  
  6. ; -Author: name22 (www.autoit.de)
  7.  
  8. Opt("GUIOnEventMode", 1)
  9.  
  10. Global $hWnd, $hDC_Window, $hDC_Bitmap, $hDC_Background, $hBitmap, $hBitmap_BG, $hImage_BG, $hOldObj, $hOldObj2, $hGraphics, $hPath_Hole, $sFile_BG
  11.  
  12. $sFile_BG = FileOpenDialog("Image Selection", "", "Images (*.*)")
  13. If @error Then Exit
  14.  
  15. Global $iWidth = 400
  16. Global $iHeight = 400
  17. Global $iRadiusHole = 80
  18.  
  19. $hWnd = GUICreate("name22 example", $iWidth, $iHeight)
  20. GUISetState()
  21.  
  22. $hDC_Window = _WinAPI_GetDC($hWnd)
  23. $hDC_Bitmap = _WinAPI_CreateCompatibleDC($hDC_Window)
  24. $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Window, $iWidth, $iHeight)
  25. $hOldObj = _WinAPI_SelectObject($hDC_Bitmap, $hBitmap)
  26.  
  27. _GDIPlus_Startup()
  28.  
  29. $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Bitmap)
  30. _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
  31.  
  32. $hImage_BG = _GDIPlus_ImageLoadFromFile($sFile_BG)
  33. $hBitmap_BG = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage_BG)
  34. _GDIPlus_ImageDispose($hImage_BG)
  35.  
  36. $hDC_Background = _WinAPI_CreateCompatibleDC($hDC_Window)
  37. $hOldObj2 = _WinAPI_SelectObject($hDC_Background, $hBitmap_BG)
  38.  
  39. $hPath_Hole = _GDIPlus_PathCreate()
  40.  
  41. OnAutoItExitRegister("_Shutdown")
  42. GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")
  43.  
  44. While Sleep(20)
  45.     _WinAPI_BitBlt($hDC_Bitmap, 0, 0, $iWidth, $iHeight, $hDC_Background, 0, 0, $SRCCOPY)
  46.  
  47.     _GDIPlus_PathReset($hPath_Hole)
  48.     _GDIPlus_PathAddEllipse($hPath_Hole, _WinAPI_GetMousePosX(True, $hWnd) - $iRadiusHole, _WinAPI_GetMousePosY(True, $hWnd) - $iRadiusHole, $iRadiusHole * 2, $iRadiusHole * 2)
  49.     _GDIPlus_GraphicsSetClipPath($hGraphics, $hPath_Hole, 4)
  50.     _GDIPlus_GraphicsClear($hGraphics)
  51.     _GDIPlus_GraphicsResetClip($hGraphics)
  52.  
  53.     _WinAPI_BitBlt($hDC_Window, 0, 0, $iWidth, $iHeight, $hDC_Bitmap, 0, 0, $SRCCOPY)
  54. WEnd
  55.  
  56. Func _Close()
  57.     Exit
  58. EndFunc
  59.  
  60. Func _Shutdown()
  61.     _WinAPI_SelectObject($hDC_Bitmap, $hOldObj)
  62.     _WinAPI_SelectObject($hDC_Background, $hOldObj2)
  63.     _WinAPI_ReleaseDC($hWnd, $hDC_Window)
  64.     _WinAPI_DeleteDC($hDC_Bitmap)
  65.     _WinAPI_DeleteDC($hDC_Background)
  66.     _WinAPI_DeleteObject($hBitmap)
  67.     _WinAPI_DeleteObject($hBitmap_BG)
  68.  
  69.     _GDIPlus_GraphicsDispose($hGraphics)
  70.     _GDIPlus_PathDispose($hPath_Hole)
  71.     _GDIPlus_Shutdown()
  72. EndFunc
  73.  
  74.  
  75. ; #FUNCTION# ====================================================================================================================
  76. ; Name...........: _GDIPlus_PathCreate
  77. ; Description ...: Creates a GraphicsPath object and initializes the fill mode
  78. ; Syntax.........: _GDIPlus_PathCreate([$iFillMode = 0])
  79. ; Parameters ....: $iFillMode - Fill mode of the interior of the path figures:
  80. ;                  |0 - The areas are filled according to the even-odd parity rule
  81. ;                  |1 - The areas are filled according to the nonzero winding rule
  82. ; Return values .: Success      - Pointer to a new GraphicsPath object
  83. ;                  Failure      - 0 and either:
  84. ;                  |@error and @extended are set if DllCall failed
  85. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  86. ; Remarks .......: After you are done with the object, call _GDIPlus_PathDispose to release the object resources
  87. ; Related .......: _GDIPlus_PathCreate2, _GDIPlus_PathDispose
  88. ; Link ..........; @@MsdnLink@@ GdipCreatePath
  89. ; Example .......; No
  90. ; ===============================================================================================================================
  91. Func _GDIPlus_PathCreate($iFillMode = 0)
  92.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreatePath", "int", $iFillMode, "int*", 0)
  93.  
  94.     If @error Then Return SetError(@error, @extended, 0)
  95.     $GDIP_STATUS = $aResult[0]
  96.     Return $aResult[2]
  97. EndFunc   ;==>_GDIPlus_PathCreate
  98.  
  99. ; #FUNCTION# ====================================================================================================================
  100. ; Name...........: _GDIPlus_PathDispose
  101. ; Description ...: Releases a GraphicsPath object
  102. ; Syntax.........: _GDIPlus_PathDispose($hPath)
  103. ; Parameters ....: $hPath - Pointer to a GraphicsPath object
  104. ; Return values .: Success      - True
  105. ;                  Failure      - False and either:
  106. ;                  |@error and @extended are set if DllCall failed
  107. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  108. ; Remarks .......: None
  109. ; Related .......: _GDIPlus_PathCreate
  110. ; Link ..........; @@MsdnLink@@ GdipDeletePath
  111. ; Example .......; No
  112. ; ===============================================================================================================================
  113. Func _GDIPlus_PathDispose($hPath)
  114.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeletePath", "hwnd", $hPath)
  115.  
  116.     If @error Then Return SetError(@error, @extended, False)
  117.     $GDIP_STATUS = $aResult[0]
  118.     Return $aResult[0] = 0
  119. EndFunc   ;==>_GDIPlus_PathDispose
  120.  
  121. ; #FUNCTION# ====================================================================================================================
  122. ; Name...........: _GDIPlus_PathAddEllipse
  123. ; Description ...: Adds an ellipse to the current figure a path
  124. ; Syntax.........: _GDIPlus_PathAddEllipse($hPath, $nX, $nY, $nWidth, $nHeight)
  125. ; Parameters ....: $hPath   - Pointer to a GraphicsPath object
  126. ;                  $nX      - The X coordinate of the upper left corner of the rectangle that bounds the ellipse
  127. ;                  $nY      - The Y coordinate of the upper left corner of the rectangle that bounds the ellipse
  128. ;                  $nWidth  - The width of the rectangle that bounds the ellipse
  129. ;                  $nHeight - The height of the rectangle that bounds the ellipse
  130. ; Return values .: Success      - True
  131. ;                  Failure      - False and either:
  132. ;                  |@error and @extended are set if DllCall failed
  133. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  134. ; Remarks .......: None
  135. ; Related .......: None
  136. ; Link ..........; @@MsdnLink@@ GdipAddPathEllipse
  137. ; Example .......; No
  138. ; ===============================================================================================================================
  139. Func _GDIPlus_PathAddEllipse($hPath, $nX, $nY, $nWidth, $nHeight)
  140.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipAddPathEllipse", "hwnd", $hPath, "float", $nX, "float", $nY, "float", $nWidth, "float", $nHeight)
  141.  
  142.     If @error Then Return SetError(@error, @extended, False)
  143.     $GDIP_STATUS = $aResult[0]
  144.     Return $aResult[0] = 0
  145. EndFunc   ;==>_GDIPlus_PathAddEllipse
  146.  
  147. ; #FUNCTION# ====================================================================================================================
  148. ; Name...........: _GDIPlus_PathReset
  149. ; Description ...: Empties a path and sets the fill mode to alternate (0)
  150. ; Syntax.........: _GDIPlus_PathReset($hPath)
  151. ; Parameters ....: $hPath - Pointer to a GraphicsPath object
  152. ; Return values .: Success      - True
  153. ;                  Failure      - False and either:
  154. ;                  |@error and @extended are set if DllCall failed
  155. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  156. ; Remarks .......: None
  157. ; Related .......: None
  158. ; Link ..........; @@MsdnLink@@ GdipResetPath
  159. ; Example .......; No
  160. ; ===============================================================================================================================
  161. Func _GDIPlus_PathReset($hPath)
  162.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipResetPath", "hwnd", $hPath)
  163.  
  164.     If @error Then Return SetError(@error, @extended, False)
  165.     $GDIP_STATUS = $aResult[0]
  166.     Return $aResult[0] = 0
  167. EndFunc   ;==>_GDIPlus_PathReset
  168.  
  169. ; #FUNCTION# ====================================================================================================================
  170. ; Name...........: _GDIPlus_GraphicsSetClipPath
  171. ; Description ...: Updates the clipping region of this Graphics object to a region that is the combination of itself and the
  172. ;                  +region specified by a graphics path
  173. ; Syntax.........: _GDIPlus_GraphicsSetClipPath($hGraphics, $hPath[, $iCombineMode = 0])
  174. ; Parameters ....: $hGraphics - Pointer to a Graphics object
  175. ;                  $hPath     - Pointer to a GraphicsPath object that specifies the region to be combined with the clipping
  176. ;                  +region of the Graphics object
  177. ;                  $iCombineMode - Regions combination mode:
  178. ;                  |0 - The existing region is replaced by the new region
  179. ;                  |1 - The existing region is replaced by the intersection of itself and the new region
  180. ;                  |2 - The existing region is replaced by the union of itself and the new region
  181. ;                  |3 - The existing region is replaced by the result of performing an XOR on the two regions
  182. ;                  |4 - The existing region is replaced by the portion of itself that is outside of the new region
  183. ;                  |5 - The existing region is replaced by the portion of the new region that is outside of the existing region
  184. ; Return values .: Success      - True
  185. ;                  Failure      - False and either:
  186. ;                  |@error and @extended are set if DllCall failed
  187. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  188. ; Remarks .......: If a figure in the path is not closed, this method treats the nonclosed figure as if it were closed by a
  189. ;                  +straight line that connects the figure's starting and ending points
  190. ; Related .......: None
  191. ; Link ..........; @@MsdnLink@@ GdipSetClipPath
  192. ; Example .......; No
  193. ; ===============================================================================================================================
  194. Func _GDIPlus_GraphicsSetClipPath($hGraphics, $hPath, $iCombineMode = 0)
  195.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipPath", "hwnd", $hGraphics, "hwnd", $hPath, "int", $iCombineMode)
  196.  
  197.     If @error Then Return SetError(@error, @extended, False)
  198.     $GDIP_STATUS = $aResult[0]
  199.     Return $aResult[0] = 0
  200. EndFunc   ;==>_GDIPlus_GraphicsSetClipPath
  201.  
  202. ; #FUNCTION# ====================================================================================================================
  203. ; Name...........: _GDIPlus_GraphicsResetClip
  204. ; Description ...: Sets the clipping region of a Graphics object to an infinite region
  205. ; Syntax.........: _GDIPlus_GraphicsResetClip($hGraphics)
  206. ; Parameters ....: $hGraphics - Pointer to a Graphics object
  207. ; Return values .: Success      - True
  208. ;                  Failure      - False and either:
  209. ;                  |@error and @extended are set if DllCall failed
  210. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  211. ; Remarks .......: None
  212. ; Related .......: None
  213. ; Link ..........; @@MsdnLink@@ GdipResetClip
  214. ; Example .......; No
  215. ; ===============================================================================================================================
  216. Func _GDIPlus_GraphicsResetClip($hGraphics)
  217.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipResetClip", "hwnd", $hGraphics)
  218.  
  219.     If @error Then Return SetError(@error, @extended, False)
  220.     $GDIP_STATUS = $aResult[0]
  221.     Return $aResult[0] = 0
  222. EndFunc   ;==>_GDIPlus_GraphicsResetClip
RAW Paste Data