繁体   English   中英

AHK打开最后打开的Windows资源管理器窗口(如果处于活动状态),否则重新开始

[英]AHK Opening last opened windows explorer window if active, else starting new

这段代码指出了当前打开的资源管理器窗口,我想打开列表中的第一个窗口,如果列表为空,则打开一个新的资源管理器。

我希望在当前鼠标位置打开/激活任一窗口

#e::
list := ""
numberOfwindows := ""
wins := ""
WinGet, id, list, ahk_class CabinetWClass ahk_exe explorer.exe
Loop, %id%
{
    numberOfwindows := A_Index
    this_ID := id%A_Index%
    WinGetTitle, title, ahk_id %this_ID%
    wins .= A_Index A_Space title ? A_Index A_Space title "`n" : "" 
}
MsgBox, number of explorer windows = %numberOfwindows%`n`n%wins%
return

这解决了。 -但是可以优化,任何人有什么建议吗?

#e::
list := ""
numberOfwindows := ""
wins := ""
WinGet, id, list, ahk_class CabinetWClass ahk_exe explorer.exe
Loop, %id%
{
    numberOfwindows := A_Index
    this_ID := id%A_Index%
    WinGetTitle, title, ahk_id %this_ID%
    if (A_Index = 1) { ; if it's the first index of the loop 
        ;MsgBox %title%
        win = %title% ; store the title in " win "
    } 
    wins .= A_Index A_Space title ?½½ A_Index A_Space title "`n" : "" 
}

IfWinNotExist ahk_class CabinetWClass
{
Run C:\Windows\explorer.exe
win := File Explorer
WinWait, %win% ahk_class CabinetWClass
WinMove, mxpos_new , mypos_new
WinActivate 
} 


;MsgBox, number of explorer windows = %numberOfwindows%`n`n%wins%
; above msgbox displays number and the names of the windows.

;~ ; we now know  the win  
; and its title, exe and class.

; we want it's current position. 
WinGetPos, X, Y, Width, Height,%win% ahk_class CabinetWClass
;MsgBox, %X%, %Y%, %Width%, %Height%  

; and we want the mouse position.
CoordMode, Mouse, Screen ; Coordinates are relative to the desktop (entire screen).
MouseGetPos, mxpos , mypos,
;MsgBox, %mxpos%, %mypos%


mxpos_new := mxpos - (Width / 2)
mypos_new := mypos - (Height / 2)

;MsgBox, %mxpos% %mypos% %Width% %Height% %mxpos_new% %mypos_new%
; activate that specific window
WinWait, %win% ahk_class CabinetWClass
WinMove, mxpos_new , mypos_new
WinActivate 
return

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM