Hallo,
ausgehend von meinem Scriptbeispiel für Slide-GUI's hatte ich mal eine UDF gebastelt.
Ich hab mich nur vorm kommentieren gescheut (übrigens war diese UDF der Grund dafür, dass DescribeIt entstanden ist)
Jetzt hab ich das mal schnell alles kommentiert und ein Beispiel erstellt.
Vielleicht nützt es ja einem was
Example
#include <WindowsConstants.au3>
#include <_SlideUDF.au3>
AutoItWinSetTitle("__DUMMY") ; Use the internal (invisible) AutoIt window as a dummy window.
$hDummyHwnd = WinGetHandle("__DUMMY") ; We will use this as parent for our gui's
; so we wont see anything on the taskbar (pretty much like $WS_EX_TOOLWINDOW)
;Create GUI on the left side.
$h_Left = GUICreate("SlideGUI left", 155, 350, -1, -1, -1, $WS_EX_TOPMOST, $hDummyHwnd)
$_Button1 = GUICtrlCreateButton("(Un-)Lock Top", 40, 40, 100, 30)
GUICtrlCreateEdit("Sample Edit...", 20, 90, 120, 200)
_Slide_WinSetSlide($h_Left, "left") ; Apply slide mode on the left side.
_Slide_SlideSetOnHover($h_Left) ; Apply slide on hover mode.
;Create GUI on the right.
$h_Right = GUICreate("SlideGUI Right", 155, 350, -1, -1, -1, $WS_EX_TOPMOST, $hDummyHwnd)
GUICtrlCreateEdit("Sample Edit...", 20, 20, 150, 300)
_Slide_WinSetSlide($h_Right, "right") ; Apply slide mode for the right side.
; No Slide on hover for this one. We want to move it by ourself.
$h_Bottom = GUICreate("SlideGUI Bottom", 350, 155, -1, -1, -1, $WS_EX_TOPMOST, $hDummyHwnd)
GUICtrlCreateCheckbox("Sample Checkbox", 40, 30)
GUICtrlCreateCombo("Combo", 140, 50)
_Slide_WinSetSlide($h_Bottom, "bottom") ; Apply slide mode
_Slide_SlideSetOnHover($h_Bottom) ; Apply slide on hover.
$h_Top = GUICreate("SlideGUI Top", 350, 155, -1, -1, -1, $WS_EX_TOPMOST, $hDummyHwnd)
$_ListView = GUICtrlCreateListView("Columnd 1|Column 2", 5, 5, 340, 145)
GUICtrlCreateListViewItem("Item 1_1|Item 1_2", $_ListView)
GUICtrlCreateListViewItem("Item 2_1|Item 2_2", $_ListView)
GUICtrlCreateListViewItem("Item 3_1|Item 3_2", $_ListView)
_Slide_WinSetSlide($h_Top, "top") ; Apply slide mode
_Slide_SlideSetOnHover($h_Top) ; Apply slide on hover.
_Slide_SlideIn($h_Top) ; Slide out top window,
_Slide_SlideSetLock($h_Top) ; Lock it, so it wont trigger the Hover-Event.
; You can also use _Slide_SlideInLock($h_Top)
$t = TimerInit()
[/autoit] [autoit][/autoit] [autoit]While 1 * Sleep(10)
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $_Button1
$fLockedState = _Slide_SlideGetLock($h_Top) ; Retrieve the "locked"-state.
Switch $fLockedState
Case False ; if not locked, slide in, and lock (so it wont trigger OnHover)
_Slide_SlideInLock($h_Top)
Case True ; if locked, slide out, and unlock (so it _will_ trigger onHover)
_Slide_SlideOutLock($h_Top, False)
EndSwitch
Case Else
If TimerDiff($t) > 3000 Then
$fSlideState = _Slide_WingetSlideState($h_Right) ; Retrive the Slide-state.
Switch $fSlideState
Case False ; If slide out, slide in.
_Slide_SlideIn($h_Right)
Case True ; If slide in, slide out.
_Slide_SlideOut($h_Right)
EndSwitch
$t = TimerInit()
EndIf
EndSwitch
WEnd
_SlideUDF.au3
Global $__SLIDE_aGUI[1][5] = [["Winhandle", "sSide", "sState", "locked", "OnHover"]]
Global $__SLIDE_hDLL = DllOpen("user32.dll") ; Open the DLL for WinIsHovered (faster with DLL-handle)
AdlibRegister("__Slide_CheckHover", 100)
OnAutoItExitRegister("__Slide_UnloadDLL")
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideGetLock()
; Description ...: Returns the "Locked"-State if a slide-GUI
; Syntax ........: _Slide_SlideGetLock($hWnd)
; Parameters ....: $hWnd - Window Handle
; Return values .: Success - Returns 1
; Failure - Returns 0 and sets @error to:
; |1 - Wrong Parameters
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Example .......: Yes
; =================================================================================================
Func _Slide_SlideGetLock($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $hWnd = $__SLIDE_aGUI[$i][0] Then Return SetError(0, 0, $__SLIDE_aGUI[$i][3])
Next
Return SetError(2, 0, 0)
EndFunc ;==>_Slide_SlideGetLock
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideIn()
; Description ...: Slides in a window.
; Syntax ........: _Slide_SlideIn($hWnd)
; Parameters ....: $hWnd - Window handle to slide
; Return values .: Success
; |None
; Failure - Returns 0 and sets @error
; |1 - Could not retrieve Window handle
; |2 - Window is not registered yet
; |3 - Window already slide in
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: The window must be registered with _Slide_WinSetSlide() first.
; =================================================================================================
Func _Slide_SlideIn($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][0] = $hWnd Then
If Not $__SLIDE_aGUI[$i][2] Then
__Slide_WinSlide($hWnd, "in", $__SLIDE_aGUI[$i][1])
$__SLIDE_aGUI[$i][2] = True
Else
Return SetError(3, 0, 0)
EndIf
EndIf
Next
Return SetError(2, 0, 0)
EndFunc ;==>_Slide_SlideIn
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideInLock()
; Description ...: Slides in and locks a window.
; Syntax ........: _Slide_SlideInLock($hWnd[, $fLocked = True])
; Parameters ....: $hWnd - Window handle to slide & lock
; $fLocked - [optional] Lock or unlock the window (default:True)
; |True - Locked
; |False - Unlocked
; Return values .: None.
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: The window must be registered with _Slide_WinSetSlide() first.
; =================================================================================================
Func _Slide_SlideInLock($hWnd, $fLocked = True)
_Slide_slideIn($hWnd)
_Slide_SlideSetLock($hWnd, $fLocked)
EndFunc ;==>_Slide_SlideInLock
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideOut()
; Description ...: Slides out a window.
; Syntax ........: _Slide_SlideOut($hWnd)
; Parameters ....: $hWnd - Window handle to slide
; Return values .: Success
; |None
; Failure - Returns 0 and sets @error
; |1 - Could not retrieve Window handle
; |2 - Window is not registered yet
; |3 - Window already slide out
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: The window must be registered with _Slide_WinSetSlide() first.
; Example .......: No
; =================================================================================================
Func _Slide_SlideOut($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][0] = $hWnd Then
If $__SLIDE_aGUI[$i][2] Then
__Slide_WinSlide($hWnd, "out", $__SLIDE_aGUI[$i][1])
$__SLIDE_aGUI[$i][2] = False
Return SetError(0, 0, 1)
Else
Return SetError(3, 0, 0)
EndIf
EndIf
Next
Return SetError(2, 0, 0)
EndFunc ;==>_Slide_SlideOut
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideOutLock()
; Description ...: Slides in and locks a window.
; Syntax ........: _Slide_SlideOutLock($hWnd[, $fLocked = True])
; Parameters ....: $hWnd - Window handle to slide
; $fLocked - [optional] Lock or unlock the window (default:True)
; |True - Locked
; |False - Unlocked
; Return values .: None.
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: The window must be registered with _Slide_WinSetSlide() first.
; Example .......: No
; =================================================================================================
Func _Slide_SlideOutLock($hWnd, $fLocked = True)
_Slide_slideOut($hWnd)
_Slide_SlideSetLock($hWnd, $fLocked)
EndFunc ;==>_Slide_SlideOutLock
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideSetLock()
; Description ...: Changes the locked state of a window.
; Syntax ........: _Slide_SlideSetLock($hWnd[, $fLocked = True])
; Parameters ....: $hWnd - Window handle to lock
; $fLocked - [optional] New locked state. (default:True)
; Return values .: Success - 1
; Failure - Returns 0 and sets @error
; |1 - Could not retrieve window handle
; |2 - Window is not registered yet
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Use this function if you want to slide out a window, which has the Slide on Hover state.
; Example .......: No
; =================================================================================================
Func _Slide_SlideSetLock($hWnd, $fLocked = True)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $hWnd = $__SLIDE_aGUI[$i][0] Then
$__SLIDE_aGUI[$i][3] = $fLocked
Return SetError(0, 0, 1)
EndIf
Next
Return SetError(2, 0, 0)
EndFunc ;==>_Slide_SlideSetLock
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_SlideSetOnHover()
; Description ...: Add or remove a Window to the slide on hover register
; Syntax ........: _Slide_SlideSetOnHover($hWnd[, $sMode = True])
; Parameters ....: $hWnd - Window handle to add / remove
; $sMode - [optional] Add or remove the Window (default:True)
; |0 - Remove from register
; |1 - Add to register
; Return values .: Success - None
; Failure - 0 and sets @error
; |1 - Could not retrieve Window handle
; Author ........: Shkal
; Modified ......: 01.03.2010
; Remarks .......: None
; Example .......: No
; =================================================================================================
Func _Slide_SlideSetOnHover($hWnd, $sMode = True)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
$iUbound = UBound($__SLIDE_aGUI)
Switch $sMode
Case True
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][0] = $hWnd Then
$__SLIDE_aGUI[$i][4] = True
EndIf
Next
Case False
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][0] = $hWnd Then
$__SLIDE_aGUI[$i][4] = False
EndIf
Next
EndSwitch
EndFunc ;==>_Slide_SlideSetOnHover
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_WinGetSlideState()
; Description ...: Returns the "Slide"-State if a slide-GUI
; Syntax ........: _Slide_WinGetSlideState($hWnd)
; Parameters ....: $hWnd - Window handle to retrieve slide state from
; Return values .: Success - Returns Slide State
; |True = slide in
; |False = slide out
; Failure - Returns 0 and sets @error to:
; |1 - Wrong Parameters
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Example .......: Yes
; =================================================================================================
Func _Slide_WinGetSlideState($hWnd)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $hWnd = $__SLIDE_aGUI[$i][0] Then Return SetError(0, 0, $__SLIDE_aGUI[$i][2])
Next
Return SetError(2, 0, -1)
EndFunc ;==>_Slide_WinGetSlideState
; #FUNCTION# ======================================================================================
; Name ..........: _Slide_WinSetSlide()
; Description ...: Add or remove a Window to the slide register
; Syntax ........: _Slide_WinSetSlide($hWnd, $sSide[, $iMode = 1])
; Parameters ....: $hWnd - Window handle to add / remove
; $sSide - Side where you want the window to be placed
; |top
; |left
; |right
; |bottom
; $iMode - [optional] Add or remove window handle from / to register (default:1)
; |1 - Add window handle
; |2 - remove window handle
; Return values .: Success - None
; Failure - 0 and sets @error
; |1 - Wrong parameters
; Author ........: SEuBo
; Modified ......: 01.03.2010
; =================================================================================================
Func _Slide_WinSetSlide($hWnd, $sSide, $iMode = 1)
If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd)
If @error Then Return SetError(1, 0, 0)
If $iMode > 1 Or $iMode < 0 Then Return SetError(1, 0, 0)
If Not StringRegExp($sSide, "(?i)(left|right|top|bottom)") Then Return SetError(1, 0, 0)
$iUbound = UBound($__SLIDE_aGUI)
Switch $iMode
Case 1
ReDim $__SLIDE_aGUI[$iUbound + 1][5]
$__SLIDE_aGUI[$iUbound][0] = $hWnd
$__SLIDE_aGUI[$iUbound][1] = $sSide
$__SLIDE_aGUI[$iUbound][2] = True
$__SLIDE_aGUI[$iUbound][3] = False
$__SLIDE_aGUI[$iUbound][4] = False
_Slide_SlideOut($hWnd)
GUISetState(@SW_SHOWNOACTIVATE, $hWnd)
Case 0
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][0] = $hWnd Then
For $j = $i To UBound($__SLIDE_aGUI) - 2
$__SLIDE_aGUI[$j][0] = $__SLIDE_aGUI[$j + 1][0]
$__SLIDE_aGUI[$j][1] = $__SLIDE_aGUI[$j + 1][1]
$__SLIDE_aGUI[$j][2] = $__SLIDE_aGUI[$j + 1][2]
$__SLIDE_aGUI[$j][3] = $__SLIDE_aGUI[$j + 1][3]
$__SLIDE_aGUI[$j][4] = $__SLIDE_aGUI[$j + 1][4]
ReDim $__SLIDE_aGUI[UBound($__SLIDE_aGUI) - 1][5]
_Slide_SlideIn($hWnd)
GUISetState(@SW_HIDE, $hWnd)
Next
EndIf
Next
EndSwitch
EndFunc ;==>_Slide_WinSetSlide
; #FUNCTION# ======================================================================================
; Name ..........: __Slide_CheckHover()
; Description ...: Internal function. This function is doing the slide-on-hover event.
; Syntax ........: __Slide_CheckHover()
; Return values .: None
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Related .......: __Slide_WinIsHovered, _Slide_SlideSetOnHover
; Example .......: No
; =================================================================================================
Func __Slide_CheckHover()
For $i = 1 To UBound($__SLIDE_aGUI) - 1
If $__SLIDE_aGUI[$i][4] Then
If Not $__SLIDE_aGUI[$i][3] Then
If __Slide_WinIsHovered($__SLIDE_aGUI[$i][0]) Then
If Not $__SLIDE_aGUI[$i][2] Then _Slide_SlideIn($__SLIDE_aGUI[$i][0])
Else
If $__SLIDE_aGUI[$i][2] Then _Slide_SlideOut($__SLIDE_aGUI[$i][0])
EndIf
EndIf
EndIf
Next
EndFunc ;==>__Slide_CheckHover
; #FUNCTION# ======================================================================================
; Name ..........: __Slide_UnloadDLL()
; Description ...: Internal function. Closes the DLL Handle, opened at startup.
; Syntax ........: __Slide_UnloadDLL()
; Return values .: None
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Related .......: __Slide_CheckHover, _Slide_SlideSetOnHover
; Example .......: No
; =================================================================================================
Func __Slide_UnloadDLL()
DllClose($__SLIDE_hDLL)
EndFunc ;==>__Slide_UnloadDLL
; #FUNCTION# ======================================================================================
; Name ..........: __Slide_WinIsHovered()
; Description ...: Internal function. Uses WinAPI PtInRect to determine weither the Window is hovered or not.
; Syntax ........: __Slide_WinIsHovered($hWnd[, $vDLL = "User32.dll"])
; Parameters ....: $hWnd - Window handle to check
; $vDLL - [optional] DLL Handle to user32.dll. (default:"User32.dll")
; |If no handle is passed, the function will open the DLL by itself. (Like _IsPressed)
; Return values .: Success - True
; Failure - False
; Author ........: Shkal
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Related .......: __Slide_CheckHover, _Slide_SlideSetOnHover
; Example .......: Yes
; =================================================================================================
Func __Slide_WinIsHovered($hWnd, $vDLL = "User32.dll")
Local $aResult, $aWPos = WinGetPos($hWnd), $aMPos = MouseGetPos()
Local $tRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
Local $iLeft = $aWPos[0], $iTop = $aWPos[1], $iWidth = $aWPos[2], $iHeight = $aWPos[3]
Local $iX = $aMPos[0], $iY = $aMPos[1]
DllStructSetData($tRect, "Left", $iLeft)
DllStructSetData($tRect, "Top", $iTop)
DllStructSetData($tRect, "Right", $iLeft + $iWidth)
DllStructSetData($tRect, "Bottom", $iTop + $iHeight)
$aResult = DllCall($vDLL, "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
If @error Then Return SetError(@error, 0, False)
Return $aResult[0] <> 0
EndFunc ;==>__Slide_WinIsHovered
; #FUNCTION# ======================================================================================
; Name ..........: __Slide_WinSlide()
; Description ...: Internal Function. This one takes care about the movement.
; Syntax ........: __Slide_WinSlide($hWnd, $sMode, $sSide)
; Parameters ....: $hWnd - Window handle
; $sMode - Mode
; |in
; |out
; $sSide - Side to slide at
; |left
; |right
; |top
; |bottom
; Return values .: None
; Author ........: SEuBo
; Modified ......: 01.03.2010
; Remarks .......: Window must be registered by _Slide_WinSetSlide first.
; Example .......: Yes
; =================================================================================================
Func __Slide_WinSlide($hWnd, $sMode, $sSide)
;$hWnd = Window to slide.
;$sMode = Slide-In or -out (in|out)
;$sSide = Side where you want the GUI to slide. (left|right|top|bottom)
Local $aScreen_Res = WinGetPos(WinGetHandle("Program Manager"))
Local $aWPos = WinGetPos($hWnd), $m = 0 - ($sMode = "in") + ($sMode = "out")
Local $h = 0 - ($sSide = "left") + ($sSide = "right"), $v = 0 - ($sSide = "top") + ($sSide = "bottom")
WinMove($hWnd, "", _ ; Move GUI according to $sMode and $sSide.
$aScreen_Res[0] - (($h = -1) * ($m = -1) * ($aWPos[2] - 10)) _
+ (($h = 1) * (($h = 1) * $aScreen_Res[2] - (10 * ($m = -1)) - ($m <> -1) * $aWPos[2])) _
+ (($h = 0) * (($h = 0) * ($aScreen_Res[2] / 2) - ($aWPos[2] / 2))) _
, _
$aScreen_Res[1] - (($v = -1) * ($m = -1) * ($aWPos[3] - 10)) _
+ (($v = 1) * (($v = 1) * $aScreen_Res[3] - (10 * ($m = -1)) - ($m <> -1) * $aWPos[3])) _
+ (($v = 0) * (($v = 0) * ($aScreen_Res[3] / 2) - ($aWPos[3] / 2))) _
)
$aWPos = WinGetPos($hWnd)
; Slide GUI.
Switch $sSide
Case "left", "right"
Local $STEP = (((($h = 1) And ($m = 1)) Or (($h = -1) And ($m = -1))) - ((($h = -1) And ($m = 1)) Or (($h = 1) And ($m = -1)))) * 10
Local $FROM = $aWPos[0], $TO = $aWPos[0] _
+ (((($h = 1) And ($m = 1)) Or (($h = -1) And ($m = -1))) * ($aWPos[2])) _
- (((($h = 1) And ($m = -1)) Or (($h = -1) And ($m = 1))) * ($aWPos[2])) - $STEP
For $i = $aWPos[0] To $TO Step $STEP
WinMove($hWnd, "", $i, $aWPos[1])
Sleep(10)
Next
Case "top", "bottom"
Local $STEP = (((($v = 1) And ($m = 1)) Or (($v = -1) And ($m = -1))) - ((($v = -1) And ($m = 1)) Or (($v = 1) And ($m = -1)))) * 10
Local $FROM = $aWPos[1], $TO = $aWPos[1] _
+ (((($v = 1) And ($m = 1)) Or (($v = -1) And ($m = -1))) * ($aWPos[3])) _
- (((($v = 1) And ($m = -1)) Or (($v = -1) And ($m = 1))) * ($aWPos[3])) - $STEP
For $i = $aWPos[1] To $TO Step $STEP
WinMove($hWnd, "", $aWPos[0], $i)
Sleep(10)
Next
EndSwitch
EndFunc ;==>__Slide_WinSlide