I think vscode command : file: reveal in file explorer uses SHOpenFolderAndSelectItems,
I went in source code and it uses this I think : shell.showItemInFolder(fullPath) from https://www.electronjs.org/docs/api/shell
chrome : chrome://downloads/, "show in folder", probably does the same thing
I want to do this https://stackoverflow.com/questions/22118653/shopenfolderandselectitems-for-explorer-replacement-program
but i don't know how to do the VARIANT parameter for this IShellWindows::RegisterPending,
here is code
I've got IShellWindows interface
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
COM_CoUninitialize()
COM_CoInitialize()
DllCall("Ole32\CoCreateInstance", "Ptr", GUID4String(CLSID_ShellWindows,"{9BA05972-F6A8-11CF-A442-00A0C90A8F39}")
, "int", 0
, "Uint", 23 ;CLSCTX_ALL ;https://altaxo.github.io/AltaxoClassReference/html/T_Altaxo_UnmanagedApi_Ole32_CLSCTX.htm
, "Ptr", GUID4String(IID_IShellWindows,"{85CB6900-4D95-11CF-960C-0080C7F4EE85}")
, "Ptr*", IShellWindows)
threadId:=DllCall("GetCurrentThreadId", UInt)
;IShellWindows::RegisterPending
DllCall(VTable(IShellWindows, 11), "Ptr", IShellWindows
, "Uint", threadId
, "Uint", 0 ;need VARIANT here
, "int", 0 ;null , do I also need a VARIANT here ?
, "Uint", 0x2 ;int ;SWC_3RDPARTY
, "Uint", cookie) ;long
return
f3::
COM_CoUninitialize()
Exitapp
COM_CoInitialize()
{
Return DllCall("ole32\CoInitialize", "Uint", 0)
}
COM_CoUninitialize()
{
DllCall("ole32\CoUninitialize")
}
VTable(ppv, idx)
{
Return NumGet(NumGet(1*ppv)+A_PtrSize*idx)
}
GUID4String(ByRef CLSID, String)
{
VarSetCapacity(CLSID, 16,0)
return DllCall("ole32\CLSIDFromString", "wstr", String, "Ptr", &CLSID) >= 0 ? &CLSID : ""
}
GUID(ByRef GUID, sGUID) ; Converts a string to a binary GUID and returns its address.
{
VarSetCapacity(GUID, 16, 0)
return DllCall("ole32\CLSIDFromString", "WStr", sGUID, "Ptr", &GUID) >= 0 ? &GUID : ""
}
is there a function/event that will be called when SHOpenFolderAndSelectItems is called ?
I use this to test SHOpenFolderAndSelectItems, replace folderPath with the parent folder, and files with the names inside you want to focus.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance, force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Explorer.exe /select,"C:\Users\Public\AHK\notes\tests\test for SH functions\test.ahk","C:\Users\Public\AHK\notes\tests\test for SH functions\test3.aac"
COM_CoUninitialize()
COM_CoInitialize()
folderPath=C:\Users\Public\AHK\notes\tests\test for SH functions
files:=["test.ahk", "test3.aac"]
DllCall("shell32\SHParseDisplayName", "Wstr", folderPath, "Uint", 0, "Ptr*", pidl, "Uint", 0, "Uint", 0)
DllCall("shell32\SHBindToObject","Ptr",0,"Ptr",pidl,"Ptr",0,"Ptr",GUID4String(IID_IShellFolder,"{000214E6-0000-0000-C000-000000000046}"),"Ptr*",pIShellFolder)
length:=files.Length()
VarSetCapacity(apidl, length * A_PtrSize, 0)
for k, v in files {
;IShellFolder:ParseDisplayName
DllCall(VTable(pIShellFolder,3),"Ptr", pIShellFolder,"Ptr",win_hwnd,"Ptr",0,"Wstr",v,"Uint*",0,"Ptr*",tmpPIDL,"Uint*",0)
NumPut(tmpPIDL, apidl, (k - 1)*A_PtrSize, "Ptr")
}
DllCall("shell32\SHOpenFolderAndSelectItems", "Ptr", pidl, "UINT", length, "Ptr", &apidl, "Uint", 0)
; "Uint",length,"Ptr",&apidl,"Ptr",GUID4String(IID_IContextMenu,"{000214E4-0000-0000-C000-000000000046}"),"UINT*",0,"Ptr*",pIContextMenu)
COM_CoUninitialize()
return
f3::
COM_CoUninitialize()
Exitapp
COM_CoInitialize()
{
Return DllCall("ole32\CoInitialize", "Uint", 0)
}
COM_CoUninitialize()
{
DllCall("ole32\CoUninitialize")
}
VTable(ppv, idx)
{
Return NumGet(NumGet(1*ppv)+A_PtrSize*idx)
}
GUID4String(ByRef CLSID, String)
{
VarSetCapacity(CLSID, 16,0)
return DllCall("ole32\CLSIDFromString", "wstr", String, "Ptr", &CLSID) >= 0 ? &CLSID : ""
}