SHOpenFolderAndSelectItems for explorer replacement program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MrDoge
Posts: 159
Joined: 27 Apr 2020, 21:29

SHOpenFolderAndSelectItems for explorer replacement program

08 Oct 2020, 17:22

I am making an explorer in ahk, currently, whenever "show in folder", the parent folder is opened, but I can't know which files to select/focus
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 : ""
    }
what does this registration do ? and how do I get the files to select/focus after I register ?
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 : ""
    }
gave92
Posts: 7
Joined: 04 Mar 2020, 08:38
Contact:

Re: SHOpenFolderAndSelectItems for explorer replacement program

19 Oct 2021, 14:40

Did you ever figure this out? I'd be really interested in knowing how to do this, thanks!
MrDoge
Posts: 159
Joined: 27 Apr 2020, 21:29

Re: SHOpenFolderAndSelectItems for explorer replacement program

08 Jul 2022, 21:44

@gave92
years later I understand c++ more

this is it:
https://github.com/FuPeiJiang/just_SHOpenFolderAndSelectItems
this can be considered an AHK library port of https://github.com/derceg/explorerplusplus/commit/67c3687f3012330d802d70028f36968788d80aff

___
add for registry (single).ah2 to registry then run test run SHOpenFolderAndSelectItems.ah2 with your directory paths

HKEY_CLASSES_ROOT\Folder\shell -> (default)
AnythingYouWant
HKEY_CLASSES_ROOT\Folder\shell\AnythingYouWant\command -> (default)
"C:\AutoHotkey_2.0-beta.3\AutoHotkey64.exe" "C:\for registry (single).ah2" "%1 "
william_ahk
Posts: 486
Joined: 03 Dec 2018, 20:02

Re: SHOpenFolderAndSelectItems for explorer replacement program

20 Feb 2024, 09:13

Thank you so much for completing this. :thumbup: I was about to get my hands dirty.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mamo691, MrDoge, ReyAHK and 238 guests