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

时间:2018-10-12 14:32:21

标签: autohotkey

此代码确定当前打开的资源管理器窗口,   我想打开列表中的第一个,如果列表为空,请打开一个   而是新的资源管理器。

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

Sub Test()
    Call ClearNamedRanges(Sheet1.Range("A1:A35000"))
End Sub

Private Sub ClearNamedRanges(ByRef oNameRange As Range)

    Dim oName As Name
    For Each oName In ActiveWorkbook.Names
        'if Not IsError(Application.Match(oName.Name, oNameRange, 0)) Then oName.RefersToRange.ClearContents
        If Not oNameRange.Find(oName.Name) Is Nothing Then oName.RefersToRange.ClearContents
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

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

#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