我想创建一个热键,用于在当前选定窗口(资源管理器窗口、程序窗口或任何窗口)的最小化和恢复之间切换,但我需要切换到最小化和恢复完全相同的窗口。如果没有选择任何窗口,则不执行任何操作。
到目前为止我已经这样做了
#s::
if (!CW)
{
WinGetPos, winWidth, winHeight, , , A
if ( winWidth == -8 and winHeight == -8)
{
WinGet, CW
WinMinimize, CW
}
} else
{
WinRestore, CW
}
这是行不通的
我也尝试过这个,
#s::
if (!%active_id%)
{
WinGet, active_id, ID, A
WinMinimize, ahk_id %active_id%
}
else
{
WinRestore, ahk_id %active_id%
}
第一次按下热键时,它会最小化窗口,第二次按下热键时,它不会恢复窗口,而是继续最小化其他窗口,依此类推。请帮忙,我需要一个切换
我从另一篇文章中找到了此示例,以寻找切换按钮,
#s::
WinGet MX, MinMax, A
If MX
WinRestore A
Else WinMaximize A
return
这个切换有效,但仅限于最大化和恢复相同窗口之间,我不想在最小化和恢复相同窗口之间切换,我想我不仅需要切换,还需要一种存储窗口 ID 的方法,这样它就能记住在窗口最小化后要恢复哪个窗口。
谢谢先进。
答案1
#s::
; If no window is already selected
; or the selected window doesn't exist anymore,
; select the currently active window and minimize it:
IfWinNotExist, ahk_id %selected_id%
{
If (IsWindow(WinExist("A")) || WinActive("ahk_class ArtRage 3"))
WinGet, selected_id, ID, A
else
{
MsgBox, No window selected
return
}
}
WinGet, WinState, MinMax, ahk_id %selected_id%
If WinState = -1 ; the selected window is minimized
{
WinRestore
selected_id := ""
}
else
WinMinimize
return
; This checks if a window is, in fact a window,
; as opposed to the desktop or a menu, etc.
IsWindow(hwnd){
WinGet, s, Style, ahk_id %hwnd%
return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}
答案2
#s::
select_window:
; If no window is already selected or the selected window doesn't exist anymore,
; select the currently active window:
IfWinNotExist, ahk_id %selected_id%
{
If IsWindow(WinExist("A"))
WinGet, selected_id, ID, A
else
{
MsgBox, No window selected
return
}
}
WinGet, WinState, MinMax, ahk_id %selected_id%
If WinState = -1 ; the window is minimized
WinRestore ahk_id %selected_id%
else
WinMinimize, ahk_id %selected_id%
return
; select another window to toggle its state:
!#s::
selected_id := ""
GoSub, select_window ; or: GoSub, #s
return
; This checks if a window is, in fact a window,
; as opposed to the desktop or a menu, etc.
IsWindow(hwnd){
WinGet, s, Style, ahk_id %hwnd%
return s & 0xC00000 ? (s & 0x100 ? 0 : 1) : 0
}