AHK Opening last opened windows explorer window 如果激活,否则开始新的

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

此代码计算出当前资源管理器 windows 打开, 我想打开列表中的第一个,如果列表为空,则打开一个 取而代之的是新的资源管理器。

我希望 open/activate 在当前鼠标位置 window

#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