name22

GDI+ Cool Window Animation

Oct 29th, 2012
165
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. #include <Misc.au3>
  6.  
  7. ; - Author: name22 (www.autoit.de)
  8. ; Warning! This script needs a specific image to function (or you could make your own image of a frame and adjust the coordinates in _DrawBG). Press F10 to display the window.
  9.  
  10. Opt("GUIOnEventMode", 1)
  11.  
  12. Global Const $nPiHalf = ACos(-1) / 2
  13. Global $vU32dll = DllOpen("user32.dll")
  14.  
  15. ;###-v-SETTINGS-v-###
  16.  
  17. $iGUIWidth = 600 ;Width of the GUI
  18. $iGUIHeight = 200 ;Height of the GUI
  19. $iDurationON = 600 ;The time it will take for the window to appear[in ms]
  20. $iDurationOFF = 400 ;The time it will take for the window to disappear [in ms]
  21.  
  22. ;###-^-SETTINGS-^-###
  23.  
  24. $tSize = DllStructCreate($tagSIZE)
  25. $pSize = DllStructGetPtr($tSize)
  26. DllStructSetData($tSize, "X", $iGUIWidth)
  27. DllStructSetData($tSize, "Y", $iGUIHeight)
  28. $tDest = DllStructCreate($tagSIZE)
  29. $pDest = DllStructGetPtr($tDest)
  30. DllStructSetData($tDest, "X", 0)
  31. DllStructSetData($tDest, "Y", 0)
  32. $tSource = DllStructCreate($tagPOINT)
  33. $pSource = DllStructGetPtr($tSource)
  34. $tBlend = DllStructCreate($tagBLENDFUNCTION)
  35. $pBlend = DllStructGetPtr($tBlend)
  36. DllStructSetData($tBlend, "Alpha", 0)
  37. DllStructSetData($tBlend, "Format", 1)
  38.  
  39. $hMain = GUICreate("Example by name22", $iGUIWidth, $iGUIHeight, Default, Default, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW))
  40. GUISetState()
  41.  
  42. $hDC_Main = _WinAPI_GetDC($hMain)
  43. $hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC_Main)
  44. $hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Main, $iGUIWidth, $iGUIHeight)
  45. _WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)
  46.  
  47. _GDIPlus_Startup()
  48.  
  49. $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
  50. _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
  51.  
  52. $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
  53.  
  54. $hImage_BG = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\bg.png")
  55. $aBG_Glass = _CutImage($hImage_BG)
  56.  
  57. GUIRegisterMsg($WM_PAINT, "_RedrawGUI")
  58. GUISetOnEvent($GUI_EVENT_CLOSE, "_Close", $hMain)
  59. OnAutoItExitRegister("_Shutdown")
  60.  
  61. HotKeySet("{F10}", "_Show")
  62.  
  63. While Sleep(1000)
  64. WEnd
  65.  
  66. Func _Show()
  67.     HotKeySet("{F10}")
  68.     Local $iTimeOffset = 0, $iTime, $vTimer = TimerInit()
  69.  
  70.     GUISetState(@SW_SHOW, $hMain)
  71.     While _IsPressed("79", $vU32dll)
  72.         $iTime = Floor(TimerDiff($vTimer))
  73.         If $iTime < $iDurationON Then
  74.             $nFrac = Sin($iTime / $iDurationON * $nPiHalf)
  75.  
  76.             $iWidthTmp = $nFrac * $iGUIWidth
  77.             $iHeightTmp = $nFrac * $iGUIHeight
  78.             $iAlphaTmp = Floor($nFrac * 0xFF)
  79.  
  80.             _GUISettings($iWidthTmp, $iHeightTmp, @DesktopWidth / 2 - $iWidthTmp / 2, @DesktopHeight / 2 - $iHeightTmp / 2, $iAlphaTmp)
  81.         EndIf
  82.         Sleep(10)
  83.     WEnd
  84.     HotKeySet("{F10}", "_Show")
  85.  
  86.     If $iTime <= $iDurationON Then
  87.         $iTimeOffset = $iDurationOFF - $iTime / $iDurationON * $iDurationOFF
  88.     EndIf
  89.     $iTime = 0
  90.     $vTimer = TimerInit()
  91.     While $iTime <= $iDurationOFF
  92.         $iTime = Floor(TimerDiff($vTimer)) + $iTimeOffset
  93.         $nFrac = Sin((1 - $iTime / $iDurationOFF) * $nPiHalf)
  94.  
  95.         $iWidthTmp = $nFrac * $iGUIWidth
  96.         $iHeightTmp = $nFrac * $iGUIHeight
  97.         $iAlphaTmp = Floor($nFrac * 0xFF)
  98.  
  99.         _GUISettings($iWidthTmp, $iHeightTmp, @DesktopWidth / 2 - $iWidthTmp / 2, @DesktopHeight / 2 - $iHeightTmp / 2, $iAlphaTmp)
  100.         Sleep(10)
  101.     WEnd
  102.     _GUISettings(0, 0, 0, 0, 0)
  103.     GUISetState(@SW_HIDE, $hMain)
  104. EndFunc
  105.  
  106. Func _GUISettings($iWidth, $iHeight, $iX = -1, $iY = -1, $iAlpha = 255)
  107.     DllStructSetData($tBlend, "Alpha", $iAlpha)
  108.     DllStructSetData($tSize, "X", $iWidth)
  109.     DllStructSetData($tSize, "Y", $iHeight)
  110.     _WinAPI_DeleteObject($hBitmap_Buffer)
  111.     _GDIPlus_GraphicsDispose($hGraphics)
  112.     $hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Main, $iWidth, $iHeight)
  113.     _WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)
  114.     $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
  115.     _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
  116.     _GDIPlus_GraphicsClear($hGraphics, 0)
  117.     _DrawBG($aBG_Glass, $iWidth, $iHeight)
  118.     If $iX = -1 And $iY = -1 Then
  119.         _RedrawGUI()
  120.     Else
  121.         DllStructSetData($tDest, "X", Floor($iX))
  122.         DllStructSetData($tDest, "Y", Floor($iY))
  123.         _WinAPI_UpdateLayeredWindow($hMain, $hDC_Main, $pDest, $pSize, $hDC_Buffer, $pSource, 0, $pBlend, $ULW_ALPHA)
  124.     EndIf
  125. EndFunc
  126.  
  127. Func _DrawBG($aBG, $iWidth, $iHeight)
  128.     _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 0)
  129.     _GDIPlus_GraphicsSetInterpolationMode($hGraphics, 5)
  130.     _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, 2)
  131.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[0], 0, 0, 20, 20) ;upper left corner
  132.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[1], 0, $iHeight - 17, 20, 17) ;lower left corner
  133.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[2], $iWidth - 21, 0, 21, 20) ;upper right corner
  134.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[3], $iWidth - 21, $iHeight - 17, 21, 17) ;lower right corner
  135.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[4], 0, 20, 20, $iHeight - 37) ;left edge
  136.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[5], $iWidth - 21, 20, 21, $iHeight - 37) ;right edge
  137.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[6], 20, 0, $iWidth - 41, 20) ;upper edge
  138.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[7], 20, $iHeight - 17, $iWidth - 41, 17) ;lower edge
  139.     _GDIPlus_GraphicsDrawImageRect($hGraphics, $aBG[8], 20, 20, $iWidth - 41, $iHeight - 37) ;center
  140.     _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
  141. EndFunc
  142.  
  143. Func _CutImage($hImage) ;Splits the image into 9 parts that can be individually scaled (prevents quality loss).
  144.     Local $aReturn[9]
  145.     $aReturn[0] = _GDIPlus_BitmapCloneArea($hImage, 0, 0, 20, 20, $GDIP_PXF32ARGB) ;upper left corner
  146.     $aReturn[1] = _GDIPlus_BitmapCloneArea($hImage, 0, 87, 20, 17, $GDIP_PXF32ARGB) ;lower left corner
  147.     $aReturn[2] = _GDIPlus_BitmapCloneArea($hImage, 86, 0, 21, 20, $GDIP_PXF32ARGB) ;upper right corner
  148.     $aReturn[3] = _GDIPlus_BitmapCloneArea($hImage, 86, 87, 21, 17, $GDIP_PXF32ARGB) ;lower right corner
  149.     $aReturn[4] = _GDIPlus_BitmapCloneArea($hImage, 0, 20, 20, 67, $GDIP_PXF32ARGB) ;left edge
  150.     $aReturn[5] = _GDIPlus_BitmapCloneArea($hImage, 86, 20, 21, 67, $GDIP_PXF32ARGB) ;right edge
  151.     $aReturn[6] = _GDIPlus_BitmapCloneArea($hImage, 20, 0, 66, 20, $GDIP_PXF32ARGB) ;upper edge
  152.     $aReturn[7] = _GDIPlus_BitmapCloneArea($hImage, 20, 87, 66, 17, $GDIP_PXF32ARGB) ;lower edge
  153.     $aReturn[8] = _GDIPlus_BitmapCloneArea($hImage, 20, 20, 66, 67, $GDIP_PXF32ARGB) ;center
  154.     Return $aReturn
  155. EndFunc
  156.  
  157. Func _RedrawGUI()
  158.     _WinAPI_UpdateLayeredWindow($hMain, $hDC_Main, 0, $pSize, $hDC_Buffer, $pSource, 0, $pBlend, $ULW_ALPHA)
  159. EndFunc
  160.  
  161. Func _Close()
  162.     Exit
  163. EndFunc   ;==>_Close
  164.  
  165. Func _Shutdown()
  166.     _WinAPI_ReleaseDC($hMain, $hDC_Main)
  167.     _WinAPI_DeleteDC($hDC_Buffer)
  168.     _WinAPI_DeleteObject($hBitmap_Buffer)
  169.  
  170.     _GDIPlus_GraphicsDispose($hGraphics)
  171.     _GDIPlus_ImageDispose($hImage_BG)
  172.     For $i = 0 To 8
  173.         _GDIPlus_BitmapDispose($aBG_Glass[$i])
  174.     Next
  175.     _GDIPlus_BrushDispose($hBrush)
  176.     _GDIPlus_Shutdown()
  177. EndFunc   ;==>_Shutdown
  178.  
  179.  
  180.  
  181. ; #FUNCTION# ====================================================================================================================
  182. ; Name...........: _GDIPlus_GraphicsSetPixelOffsetMode
  183. ; Description ...: Sets the pixel offset mode of a Graphics object
  184. ; Syntax.........: _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $iPixelOffsetMode)
  185. ; Parameters ....: $hGraphics        - Pointer to a Graphics object
  186. ;                  $iPixelOffsetMode - Pixel offset mode:
  187. ;                  |0,1,3 - Pixel centers have integer coordinates
  188. ;                  |2,4   - Pixel centers have coordinates that are half way between integer values (i.e. 0.5, 20, 105.5, etc...)
  189. ; Return values .: Success      - True
  190. ;                  Failure      - False and either:
  191. ;                  |@error and @extended are set if DllCall failed
  192. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  193. ; Remarks .......: None
  194. ; Related .......: _GDIPlus_GraphicsGetPixelOffsetMode
  195. ; Link ..........; @@MsdnLink@@ GdipSetPixelOffsetMode
  196. ; Example .......; No
  197. ; ===============================================================================================================================
  198. Func _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $iPixelOffsetMode)
  199.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "hwnd", $hGraphics, "int", $iPixelOffsetMode)
  200.  
  201.     If @error Then Return SetError(@error, @extended, False)
  202.     $GDIP_STATUS = $aResult[0]
  203.     Return $aResult[0] = 0
  204. EndFunc   ;==>_GDIPlus_GraphicsSetPixelOffsetMode
  205.  
  206. ; #FUNCTION# ====================================================================================================================
  207. ; Name...........: _GDIPlus_GraphicsSetInterpolationMode
  208. ; Description ...: Sets the interpolation mode of a Graphics object
  209. ; Syntax.........: _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
  210. ; Parameters ....: $hGraphics          - Pointer to a Graphics object
  211. ;                  $iInterpolationMode - Interpolation mode:
  212. ;                  |0 - Default interpolation mode
  213. ;                  |1 - Low-quality mode
  214. ;                  |2 - High-quality mode
  215. ;                  |3 - Bilinear interpolation. No prefiltering is done
  216. ;                  |4 - Bicubic interpolation. No prefiltering is done
  217. ;                  |5 - Nearest-neighbor interpolation
  218. ;                  |6 - High-quality, bilinear interpolation. Prefiltering is performed to ensure high-quality shrinking
  219. ;                  |7 - High-quality, bicubic interpolation. Prefiltering is performed to ensure high-quality shrinking
  220. ; Return values .: Success      - True
  221. ;                  Failure      - False and either:
  222. ;                  |@error and @extended are set if DllCall failed
  223. ;                  |$GDIP_STATUS contains a non zero value specifying the error code
  224. ; Remarks .......: The interpolation mode determines the algorithm that is used when images are scaled or rotated
  225. ; Related .......: _GDIPlus_GraphicsGetInterpolationMode
  226. ; Link ..........; @@MsdnLink@@ GdipSetInterpolationMode
  227. ; Example .......; No
  228. ; ===============================================================================================================================
  229. Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
  230.     Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)
  231.  
  232.     If @error Then Return SetError(@error, @extended, False)
  233.     $GDIP_STATUS = $aResult[0]
  234.     Return $aResult[0] = 0
  235. EndFunc   ;==>_GDIPlus_GraphicsSetInterpolationMode
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×