0

edit : I think I found the functions needed, but I don't know how to catch this IShellWindows::OnNavigate, this is not a function I call, but a function that IS CALLED.

while writing my question, I found this in similar questions, which is exactly what I need

SHOpenFolderAndSelectItems for explorer replacement program

IShellWindows::RegisterPending

Type: VARIANT*

A VARIANT of type VT_VARIANT | VT_BYREF. Set the value of pvarloc to an absolute PIDL (PIDLIST_ABSOLUTE) that specifies the window to register.

I've only used SHParseDisplayName before which gives a PIDL, but that's for a file path, how can I get PIDL of a window ? What does PIDL of a window mean ?

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've asked this question in the ahk forums before because I am writing a file manager in ahk, I would like to call these dll functions in ahk. There is what I've tried in ahk.

I'm not sure : does GetCurrentThreadId give the correct thread ID for long lThreadId ?

Mr. Doge
  • 796
  • 5
  • 11
  • PIDLs aren't just for files/folders, they represent most objects within the Shell (see [Common Explorer Concepts](https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/cc144089(v=vs.85))). So, if a window can be accessed via Shell interfaces, then it needs a PIDL to represent it within the Shell folder/namespace that the window belongs to. – Remy Lebeau Oct 09 '20 at 20:49
  • but how to get PIDL of a window ? is this how ? [IPersistFolder2::GetCurFolder](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ipersistfolder2-getcurfolder) its from [here](https://stackoverflow.com/questions/22284718/how-to-get-the-pidl-of-an-open-explorer-window), but that is for an open explorer window, and IShellWindows::RegisterPending is for a window that is pending open... – Mr. Doge Oct 09 '20 at 23:14
  • Windows don't have PIDLs. A PIDL is an identifier for a Shell Item or Shell Folder. Folders have shell views (IShellView) and folder views (IFolderView), views have windows (HWND and IOleWindow). So when you see mentioned a window's PIDL, it's a shortcut for the PIDL of the folder that defines the view(s). – Simon Mourier Oct 09 '20 at 23:23
  • ty. I don't get the point/use of the window... what folder should it be ? which view should it be ? (shell/folder) Do I still use SHParseDisplayName to get PIDL ? then SHBindToObject to get IShellFolder, then IShellFolder::CreateViewObject to get IShellView, then IShellView::CreateViewWindow to get the window ? how can this get me the files that I should reveal/focus/select when "Show in folder" ? Edit : I didn't find CreateViewWindow in IFolderView – Mr. Doge Oct 10 '20 at 00:26
  • 1
    If you have a window that's showing the contents of C:\, the PIDL you register would be the PIDL for C:\. That way when the shell wants to display the contents of C:\ it can tell it has a window registered that's already showing C:\ and so it doesn't need to open a new window showing C:\. – Jonathan Potter Oct 10 '20 at 00:56
  • ty. how can I know when shell wants to display the contents ? Even if it's already showing C:\, I don't want it to do nothing, I need to focus/select the files in C:\ specified in SHOpenFolderAndSelectItems. And what happens if the window is not showing C:\ ? I need the folder to browse to and the files to focus/select – Mr. Doge Oct 10 '20 at 01:39
  • sorry I forgot about [IShellWindows::OnNavigate](https://learn.microsoft.com/en-us/windows/win32/api/exdisp/nf-exdisp-ishellwindows-onnavigate), it seems that that is the event, but I think it only specifies the new location and I need the files to focus – Mr. Doge Oct 10 '20 at 13:37
  • this selects items : [IShellView::SelectItem](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishellview-selectitem), but it is not an event – Mr. Doge Oct 10 '20 at 13:48
  • I think I found it, I need to call [IFolderView2::GetSelection](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ifolderview2-getselection) after IShellWindows::OnNavigate has been triggered – Mr. Doge Oct 10 '20 at 17:32
  • what example ? I found this https://www.codeproject.com/Articles/17809/Host-Windows-Explorer-in-your-applications-using-t that is using this [IExplorerBrowserEvents::OnNavigationComplete](https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-iexplorerbrowserevents-onnavigationcomplete), but it's in c++ – Mr. Doge Oct 12 '20 at 23:59
  • `but it's in c++ ` , In which language do you need to compile? If it is not C++, please remove the c++ tag. – Strive Sun Oct 14 '20 at 07:24
  • It is useful (the codeproject link), but I don't understand it, so I need to understand it... – Mr. Doge Oct 14 '20 at 15:19
  • According to the article you provided, running `SHParseDisplayName(szPath, NULL, &pidlBrowse, 0, NULL)` and we get the pidl, then call `BrowseToIDList` method which accepts the item ID list of a Shell folder to which the browser navigates. `OnNavigationComplete` is used to notify clients that the Explorer browser has successfully navigated to a Shell folder. I'm not sure if it meets your need. – Strive Sun Oct 16 '20 at 09:08
  • The demo is a MFC application. `CExplorerBrowserView` is a derived class of `CView`. For the knowledge of MFC class, I suggest you post a new thread about MFC to ask about the CView class. – Strive Sun Oct 16 '20 at 09:31

1 Answers1

0

years later I can answer my question
https://github.com/FuPeiJiang/just_SHOpenFolderAndSelectItems
the code is there but the explanation isn't quite

taken from c++ version (that I understand now (the explanations are plenty))
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 "

Mr. Doge
  • 796
  • 5
  • 11