[AHK V2]鼠标悬停展开窗口,鼠标离开折叠窗口

发布于:2024-07-04 ⋅ 阅读:(17) ⋅ 点赞:(0)

演示鼠标悬停窗口标题栏则展开窗口,鼠标离开窗口标题栏则折叠窗口。

;作者:sunwind
;日期:2024年6月30日11:36:08
;脚本:演示鼠标悬停窗口标题栏则展开窗口,鼠标离开窗口标题栏则折叠窗口。
MyGui := Gui()
mytext:=MyGui.Add("Text",, "Please enter your name:")
MyGui.AddEdit("vName")
MyGui.always:=0
MyGui.mode:="折叠"
MyGui.Title:="悬停展开,离开折叠"
MyGui.OnEvent("Close", myGui_Close)
myGui_Close(thisGui) {  ; 声明中 this 参数是可选的.
    if MsgBox("Are you sure you want to close the GUI?",, "y/n") = "No"
        return true  ; true = 1
    else
        {
         MyGui.Destroy 
         ExitApp
        }
}
MyGui.Show("w300 h1")
OnMessage( WM_MOUSEMOVE := 0xA0, onNcMouseMove  )
OnMessage( WM_NCMOUSELEAVE := 0x2A2,  onNcMouseLeave)

onNcMouseMove(wParam, lParam, msg, hwnd) {
    if  (MyGui.mode="折叠")
        {
            OutputDebug "折叠->展开"
            WinMove , ,300,200, MyGui.Title
            MyGui.mode:="展开"
        }
    }

onNcMouseLeave(wParam, lParam, msg, hwnd) {
    if  (MyGui.mode="展开" and MyGui.always!=1)
        {
            OutputDebug "展开->折叠"
            try
                {
                    WinMove , ,300,28, MyGui.Title 
                    MyGui.mode:="折叠"
                }  
        }
}
#HotIf overTitleBar()
RButton::
{
    ; OutputDebug overTitleBar()
    MyGui.always:= !MyGui.always
    if(MyGui.always)
        {
            try
                {
                    WinMove , ,300,200, MyGui.Title
                    ToolTip "持续展开"
                }
        }
    Else
        {
            ToolTip "鼠标悬停展开"
        }
    SetTimer(ToolTip,-1000)
} 
#HotIf

overTitleBar() { 
    ; https://www.autohotkey.com/boards/viewtopic.php?t=31119
    CoordMode("Mouse")
    MouseGetPos(&x, &y, &hWnd)
    ErrorLevel := SendMessage(WM_NCHITTEST := 0x84, 0, x | y << 16, , "ahk_id " hWnd)
    Return (ErrorLevel = HTCAPTION := 2) and (hWnd=MyGui.Hwnd)
   }