Search code examples
winapiexplorershell-extensionshresultapimonitor

Showing 'This folder is empty' background when my shell extension folder is empty


In my shell extension, I want to mimic explorer's behavior and show 'This folder is empty' message when in fact my folder is empty:

ThisFolderIsEmpty

However, I can't accomplish it.

Using API Monitor, I see that when explorer refreshes an empty folder, IEnumIDList::Next() is returning the following:

APIMonitorScreenshot

Meaning, that the 'next' item returned is NULL, the number of items is 0 and the result is S_FALSE.

As mentioned, I tried to mimic the return values, and indeed no items are loaded for the folder, but no message appear either.

So what API would trigger this message?


Solution

  • Your IEnumIDList implementation must implement IObjectWithSite. Sample of implementation:

      var
        ServiceProvider: IServiceProvider;
        ShellBrowser: IShellBrowser;
        ShellView: IShellView;
        FolderView2: IFolderView2;
      begin
        if not Assigned(ASite) then Exit;
        OleCheck(ASite.QueryInterface(IServiceProvider, ServiceProvider));
        try
          OleCheck(ServiceProvider.QueryService(SID_STopLevelBrowser, IShellBrowser, ShellBrowser));
          try
            OleCheck(ShellBrowser.QueryActiveShellView(ShellView));
            try
              OleCheck(ShellView.QueryInterface(IFolderView2, FolderView2));
              try
                FolderView2.SetText(FVST_EMPTYTEXT, 'The message you want to see');
              finally
                FolderView2 := nil;
              end;
            finally
              ShellView := nil;
            end;
          finally
            ShellBrowser := nil;
          end;
        finally
          ServiceProvider := nil;
        end;
      end;
    

    Result:

    enter image description here

    Also you can use the same code in your IShellFolder implementation.