name22

GUI slide in/out on mousehover

Apr 6th, 2013
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GUIConstants.au3>
  2. #include <WindowsConstants.au3>
  3. #Include <APIConstants.au3>
  4. #include <WinAPI.au3>
  5. #include <Constants.au3>
  6.  
  7. ; - Author: name22 (www.autoit.de)
  8.  
  9. $iGUI_Width = 400 ;GUI Breite
  10. $iGUI_Height = 100 ;GUI Höhe
  11.  
  12. $iMinHeight = 10 ;Größe des sichtbaren Teils der GUI (wenn sie versteckt ist)
  13. $iGUI_XPos = @DesktopWidth / 2 + 300 ;X-Position der GUI
  14. $iGUI_YPos = $iMinHeight - $iGUI_Height ;Y-Position der GUI
  15.  
  16. $iHovertime = 1000 ;Zeit (in ms) die der Zeiger über dem Fenster verbringen muss, bis es eingeblendet wird
  17. $iSpeed = 5 ;Geschwindigkeit der Einblendung
  18. $bSliding = False
  19.  
  20. $hGUI = GUICreate("Slide in/out", $iGUI_Width, $iGUI_Height, $iGUI_XPos, $iGUI_YPos, $WS_POPUP)
  21. GUISetState()
  22.  
  23. _WinAPI_TrackMouseEvent($hGUI, BitOR($TME_HOVER, $TME_LEAVE), $iHovertime)
  24.  
  25. GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
  26. GUIRegisterMsg($WM_MOUSEHOVER, "WM_MOUSEHOVER")
  27. GUIRegisterMsg($WM_MOUSELEAVE, "WM_MOUSELEAVE")
  28.  
  29. While True
  30.     Switch GUIGetMsg()
  31.         Case $GUI_EVENT_CLOSE
  32.             Exit
  33.     EndSwitch
  34. WEnd
  35.  
  36. Func WM_MOUSEMOVE($hWnd, $iMsg, $wParam, $lParam)
  37.     _WinAPI_TrackMouseEvent($hGUI, BitOR($TME_HOVER, $TME_LEAVE), $iHovertime)
  38. EndFunc
  39.  
  40. Func WM_MOUSEHOVER($hWnd, $iMsg, $wParam, $lParam)
  41.     If Not $bSliding Then
  42.         $bSliding = True
  43.         AdlibRegister("_GUISlide", 20)
  44.     EndIf
  45. EndFunc
  46.  
  47. Func WM_MOUSELEAVE($hWnd, $iMsg, $wParam, $lParam)
  48.     If $bSliding Then
  49.         $bSliding = False
  50.         AdlibUnRegister("_GUISlide")
  51.         $iGUI_YPos = $iMinHeight - $iGUI_Height
  52.         _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $iGUI_XPos, $iGUI_YPos, 0, 0, $SWP_NOSIZE)
  53.     EndIf
  54. EndFunc
  55.  
  56. Func _GUISlide()
  57.     If Not $bSliding Then Return
  58.     If $iGUI_YPos < 0 Then
  59.         $iGUI_YPos += $iSpeed
  60.     ElseIf $iGUI_YPos > 0 Then
  61.         $iGUI_YPos = 0
  62.     EndIf
  63.  
  64.     _WinAPI_SetWindowPos($hGUI, $HWND_TOP, $iGUI_XPos, $iGUI_YPos, 0, 0, $SWP_NOSIZE)
  65. EndFunc
  66.  
  67.  
  68. ; #FUNCTION# ====================================================================================================================
  69. ; Name...........: _WinAPI_TrackMouseEvent
  70. ; Description....: Posts messages when the mouse pointer leaves a window or hovers over a window for a specified amount of time.
  71. ; Syntax.........: _WinAPI_TrackMouseEvent ( $hWnd, $iFlags [, $iTime] )
  72. ; Parameters.....: $hWnd   - Handle to the window to track.
  73. ; Return values..: $iFlags - The services requested. This parameter can be a combination of the following values.
  74. ;
  75. ;                            $TME_CANCEL
  76. ;                            $TME_HOVER
  77. ;                            $TME_LEAVE
  78. ;                            $TME_NONCLIENT
  79. ;                            $TME_QUERY
  80. ;
  81. ;                  $iTime  - The hover time-out (if $TME_HOVER was specified in $Flags), in milliseconds. Can be (-1), which
  82. ;                            means to use the system default hover time-out.
  83. ;                  Failure - 0 and sets the @error flag to non-zero.
  84. ; Author.........: Matt Diesel (Mat)
  85. ; Modified.......: Yashied
  86. ; Remarks........: None
  87. ; Related........:
  88. ; Link...........: @@MsdnLink@@ TrackMouseEvent
  89. ; Example........: Yes
  90. ; ===============================================================================================================================
  91.  
  92. Func _WinAPI_TrackMouseEvent($hWnd, $iFlags, $iTime = -1)
  93.  
  94.     Local $tTME = DllStructCreate('dword;dword;hwnd;dword')
  95.  
  96.     DllStructSetData($tTME, 1, DllStructGetSize($tTME))
  97.     DllStructSetData($tTME, 2, $iFlags)
  98.     DllStructSetData($tTME, 3, $hWnd)
  99.     DllStructSetData($tTME, 4, $iTime)
  100.  
  101.     Local $Ret = DllCall('user32.dll', 'int', 'TrackMouseEvent', 'ptr', DllStructGetPtr($tTME))
  102.  
  103.     If (@error) Or (Not $Ret[0]) Then
  104.         Return SetError(1, 0, 0)
  105.     EndIf
  106.     Return 1
  107. EndFunc   ;==>_WinAPI_TrackMouseEvent
RAW Paste Data