本帖最後由 rictirse 於 2014-12-24 08:36 編輯
我自己也寫了一個伸縮窗口,
窗口是從上方往下滑出.
<滑出前>
<已滑出>
----------------------------------------------------------------------------------- HotKeySet("{ESC}", "_Ex")
- #include <WindowsConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <EditConstants.au3>
- #include <GUIStatusBar.au3>
- #include <Array.au3>
- $wait = 1 * Sleep(10)
- $dll = DllOpen("user32.dll")
- $topWin = GUICreate("我是伸縮視窗", 200, 255, -1, -1, -1, $WS_EX_TOPMOST)
- Global $LEFT_in = False
- Global $RIGHT_in = False
- Global $BOTTOM_in = False
- Global $topWin_in = False
- _winOut($topWin, "out", "top")
- $editWin = GUICtrlCreateEdit("", 0, 0, 200, 235, $ES_READONLY)
- GUICtrlSetBkColor(-1, 0xFFE0E8)
- GUICtrlSetData(-1, "I" & @CRLF &"Love" & @CRLF &"Microduo!!")
- GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
- GUICtrlSetColor(-1, 0xff0000)
- Local $sTxt[1] = ["By Bunnie"]
- $byMe = _GUICtrlStatusBar_Create($topWin, 522, $sTxt)
- GUISetState(@SW_SHOWNOACTIVATE, $topWin)
- While $wait
- $nMsg = GUIGetMsg(1)
- Select
- Case $nMsg[0] = -3
- _Ex()
- Case _mouseToHovered($topWin, $dll)
- If Not $topWin_in Then
- _winOut($topWin, "in", "top")
- $topWin_in = True
- EndIf
- Case Else
- Select
- Case $topWin_in
- _winOut($topWin, "out", "top")
- $topWin_in = False
- EndSelect
- EndSelect
- WEnd
- Func _mouseToHovered($hWnd, $vDLL = "User32.dll") ;==>滑鼠碰到就滑出
- Local $result
- Local $wPos = WinGetPos($hWnd)
- Local $mPos = MouseGetPos()
- Local $rect = DllStructCreate("int Left;int Top;int Right;int Bottom")
- Local $left = $wPos[0], $top = $wPos[1], $iWidth = $wPos[2], $iHeight = $wPos[3]
- Local $iX = $mPos[0], $iY = $mPos[1]
- DllStructSetData($rect, "Left", $left)
- DllStructSetData($rect, "Top", $top)
- DllStructSetData($rect, "Right", $left + $iWidth)
- DllStructSetData($rect, "Bottom", $top + $iHeight)
- $result = DllCall($vDLL, "int", "PtInRect", "ptr", DllStructGetPtr($rect), "int", $iX, "int", $iY)
- If @error Then
- Return SetError(@error, 0, False)
- EndIf
- Return $result[0] <> 0
- EndFunc
- Func _winOut($hWnd, $mode, $side) ;==>視窗滑出
- Local $h = 0 - ($side = "left") + ($side = "right"), $v = 0 - ($side = "top") + ($side = "bottom")
- Local $wPos = WinGetPos($hWnd), $m = 0 - ($mode = "in") + ($mode = "out")
- Local $screen_Rs = WinGetPos(WinGetHandle("Program Manager"))
- WinMove($hWnd, "", _
- $screen_Rs[0] - (($h = -1) * ($m = -1) * ($wPos[2] - 10)) _
- + (($h = 1) * (($h = 1) * $screen_Rs[2] - (10 * ($m = -1)) - ($m <> -1) * $wPos[2])) _
- + (($h = 0) * (($h = 0) * ($screen_Rs[2] / 2) - ($wPos[2] / 2))) _
- , _
- $screen_Rs[1] - (($v = -1) * ($m = -1) * ($wPos[3] - 10)) _
- + (($v = 1) * (($v = 1) * $screen_Rs[3] - (10 * ($m = -1)) - ($m <> -1) * $wPos[3])) _
- + (($v = 0) * (($v = 0) * ($screen_Rs[3] / 2) - ($wPos[3] / 2))) _
- )
- $wPos = WinGetPos($hWnd)
- Switch $side
- 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 = $wPos[1], $TO = $wPos[1] _
- + (((($v = 1) And ($m = 1)) Or (($v = -1) And ($m = -1))) * ($wPos[3])) _
- - (((($v = 1) And ($m = -1)) Or (($v = -1) And ($m = 1))) * ($wPos[3])) - $STEP
- For $i = $wPos[1] To $TO Step $STEP
- WinMove($hWnd, "", $wPos[0], $i)
- Sleep(10)
- Next
- Case "right", "left"
- 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 = $wPos[0], $TO = $wPos[0] _
- + (((($h = 1) And ($m = 1)) Or (($h = -1) And ($m = -1))) * ($wPos[2])) _
- - (((($h = 1) And ($m = -1)) Or (($h = -1) And ($m = 1))) * ($wPos[2])) - $STEP
- For $i = $wPos[0] To $TO Step $STEP
- WinMove($hWnd, "", $i, $wPos[1])
- Sleep(10)
- Next
- EndSwitch
- EndFunc
- Func _Ex() ;==>離開
- DllClose($dll)
- Exit
- EndFunc
複製代碼
|