1

For what I understand File Explorer uses a list-view control to display the files. (For example How do I arrange or sort the desktop icons in c#?).

If I have an object that implements IShellView is it possible to get the window handle that could be used with LVM messages? LVM messages like these https://learn.microsoft.com/en-us/windows/desktop/Controls/bumper-list-view-control-reference-messages require handle of type HWND to be sent messages to.

Mr. Ran Dum
  • 151
  • 8
  • This would rely on specific implementation details. Can't you use the shell API to achieve your goal? – David Heffernan Feb 01 '19 at 14:58
  • 1
    ask for [`IFolderView`](https://learn.microsoft.com/en-us/windows/desktop/api/shobjidl_core/nn-shobjidl_core-ifolderview) from your `IShellView` interface. anyway `IShellView::GetWindow` can be used – RbMm Feb 01 '19 at 15:00
  • 2
    the `IShellView::GetWindow` return `SHELLDLL_DefView` class window, it child can be `DirectUIHWND` not `SysListView32` – RbMm Feb 01 '19 at 15:17
  • 5
    File Explorer stopped using a ListView control back in Windows 7, I believe. It certainly hasn't used one for a long time, except in one place (the desktop). – Raymond Chen Feb 01 '19 at 15:38
  • Thank you so much everyone. It doesnt make sense for me to use this then. I was looking for a less expensive alternative to IShellWindow::Refresh to force File Explorer to resort files. – Mr. Ran Dum Feb 01 '19 at 16:22
  • 2
    Always best to ask about the actual problem – David Heffernan Feb 01 '19 at 17:06

2 Answers2

2

The following function found on the net re-classes DirectUIHWND control into the familiar SysListView32. However the change is not propagated until you double-click on the list-view items, manually change directories.

Be aware that every time you go to a different directory then the list-view presented for that directory has a different handle, which makes the task of sub-classing the control a kind of 'challenging'.

I still have to figure how to restore the list-view with the following function and refreshing without having to use mouse double-clicks.

void RevertExplorerToListView(HWND explorerHandle)

{ IShellWindows* shellWindow;

if (SUCCEEDED(CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_ALL, IID_IShellWindows,
    reinterpret_cast<void**>(&shellWindow))))
{
    VARIANT v;
    V_VT(&v) = VT_I4;
    IDispatch* dispatch;
    BOOL found = FALSE;

    for (V_I4(&v) = 0; !found && shellWindow->Item(v, &dispatch) == S_OK; V_I4(&v)++)
    {
        IWebBrowserApp* browserApp;

        if (SUCCEEDED
        (dispatch->QueryInterface(IID_IWebBrowserApp, reinterpret_cast<void**>(&browserApp))))
        {
            HWND appHandle;
            
            if(SUCCEEDED
            (browserApp->get_HWND(reinterpret_cast<LONG_PTR*>(&appHandle))) && appHandle == explorerHandle)
            {
                found = TRUE;
                IServiceProvider* provider;

                if (
                    SUCCEEDED(browserApp->QueryInterface(IID_IServiceProvider, reinterpret_cast<void**>(&provider))))
                {
                    IShellBrowser* browser;

                    if (
                        SUCCEEDED(provider->QueryService(SID_STopLevelBrowser, IID_IShellBrowser, reinterpret_cast<void**>(&browser))))
                    {
                        IFolderViewOptions* options;
                        if (SUCCEEDED(browser->QueryInterface(IID_IFolderViewOptions,
                            reinterpret_cast<void**>(&options))))
                        {
                            if (FAILED(options->SetFolderViewOptions(FVO_VISTALAYOUT, FVO_VISTALAYOUT)))
                            {
                            }
                            options->Release();
                        }
                        browser->Release();
                    }
                    provider->Release();
                }
            }
            browserApp->Release();
        }
    }
    shellWindow->Release();
}

}

khalfan
  • 23
  • 6
1

Like Raymond Chen explained in his comment ListView is not used anymore except on the desktop.

Mr. Ran Dum
  • 151
  • 8