!P::{
try Explorer_Navigate_New_Tab("D:\Project")
Return
}
Explorer_Navigate_New_Tab(FullPath, hwnd := "") {
if (hwnd) { ; make sure this Explorer window is active
WinActivate("ahk_id " hwnd)
WinWaitActive("ahk_id " hwnd)
}
else
hwnd := WinExist("A") ; if omitted, use active window
ProcessName := WinGetProcessName("ahk_id " hwnd)
if (ProcessName != "explorer.exe") ; not Windows explorer
return
if (FullPath = "") {
Send("^t") ; add a new tab
return
}
; Windows Explorer is the active window
Send("^t") ; add a new tab
; Note 1: This hotkey works in English and French, don't know for other localizations
; Note 2: AFAIK, this hotkey does nothing in earlier versions of Windows Explorer but
; it would be safer to check the version before sending it
Sleep(100) ; for safety
; the new tab is the active tab
Explorer_Navigate_Tab(FullPath, hwnd)
}
Explorer_Navigate_Tab(FullPath, hwnd := "") {
; originally from Learning one (https://www.autohotkey.com/boards/viewtopic.php?p=4480#p4480)
; adapted by JnLlnd for tabbed browsing new to Windows 11 version 22H2 (build 22621.675)
; with code from ntepa (https://www.autohotkey.com/boards/viewtopic.php?p=488735#p488735)
; also works with previous versions of Windows Explorer
hwnd := (hwnd = "") ? WinExist("A") : hwnd ; if omitted, use active window
ProcessName := WinGetProcessName("ahk_id " hwnd)
if (ProcessName != "explorer.exe") ; not Windows explorer
return
for pExp in ComObject("Shell.Application").Windows {
if (pExp.hwnd = hwnd) { ; matching window found
activeTab := 0
try activeTab := ControlGetHwnd("ShellTabWindowClass1", "ahk_id" hwnd)
if activeTab {
static IID_IShellBrowser := "{000214E2-0000-0000-C000-000000000046}"
shellBrowser := ComObjQuery(pExp, IID_IShellBrowser, IID_IShellBrowser)
;thisTab:=DllCall(NumGet(ComObjValue(shellBrowser),3*A_PtrSize, "UPtr"), "Ptr", shellBrowser, "UInt*")
ComCall(3, shellBrowser, "uint*", &thisTab := 0)
if (thisTab != activeTab) ; matching active tab
continue
ObjRelease(ComObjValue(shellBrowser))
}
pExp.Navigate("file:///" FullPath)
return
}
}
}