Your best source of information and news about Vista hardware, BIOS and drivers on the internet

Vista ARTICLES TOP 50 Spyware Virus Vista SOFT Vista HELP

Shell Namespace Extension: Enabling Deep Search


Overview

From my past posts about implementing your own Shell Namespace, there have been some great questions posted by readers.  Many of these stem from the fact that the Namespace example is fairly simple in that it does not implement all of the behavior that is possible in Explorer.  This was done to focus on the core steps in getting a working Namespace implemented.  Yet, there are a few extra steps you can take that don’t require too much more coding on your part to add more useful features.  One question in particular that comes up quite often is how to enable deep searching in your Namespace.

You will notice from the existing Namespace example that if you enter a search term in the search box in Explorer, the search only filters items that are currently in the view.  It does not search into the folders.  In the below images, we try to search for “Two” in the search box which only results in 1 item.  Thus, the sub folders were not included.

Filter Search

Filter Results - shallow

What does a Namespace implementer have to do in order to include sub folders in their namespace search results?  This is actually fairly simple.

Implementing IShellFolderViewCB and IFolderViewSettings

In our previous code, we did not implement an IShellFolderViewCB for our Namespace.  This allows your Namespace to be notified of events associated with the view.  An implementation of IShellFolderViewCB can be specified in your call to SHCreateShellFolderView.  This is optional and previously we were just passing NULL for this.   We need to create a class that implements IShellFolderViewCB as well as IFolderViewSettings.  For our IFolderViewSettings implementation, we only need to provide a handler for the GetFolderFlags method.  It is through this method that we notify the Shell that we want to perform deep searches within our Namespace.

IFACEMETHODIMP CFolderViewCB::GetFolderFlags(__out FOLDERFLAGS *pfolderMask, __out FOLDERFLAGS *pfolderFlags)

{

    if (pfolderMask)

    {

        *pfolderMask = FWF_USESEARCHFOLDER;

    }

    if (pfolderFlags)

    {

        *pfolderFlags = FWF_USESEARCHFOLDER;

    }

   

    return S_OK;

} 

As you can see from the above implementation of GetFolderFlags, we only care to notify the Shell of the FWF_USESEARCHFOLDER flag.  This tells the Shell that our Namespace should use the Search Folder for performing stacking and searching.  You could also specify other flags to modify the appearance and behavior of your namespace.

The modified code for this sample is linked below.  You will notice that the implementation of IShellFolderViewCB and IFolderViewSettings is rather sparse – most methods just return E_NOTIMPL as we are not using them here.   You can implement these yourself if you see the need to extend your code.
Now that we have notified the Shell to use the Search Folder, we can perform deep searches within our Namespace.  When we perform the same search we did previously, we now get the following results:

deep search

This Namespace simply generates 10 virtual items to a default depth of 5.  The Search enumerates the contents of the Namespace to that depth.  It should also be called out that we had to implement our namespace's ParseDisplayName method in order for our namespace to function in the Search folder.

*Please note that the method described here only works with the default shell view (Defview).  It is not supported for custom IShellView implementations.

Building the FolderView SDK Sample

  1. To build the FolderViewImpl sample, be sure to download and install the Windows SDK.
  2. Download the modified FolderView SDK sample
  3. Launch FolderViewImpl.sln in Visual Studio (The solution file is for Visual Studio 2008)
  4. Open the properties for the project
  5. Add a path to the SDK includes to the C/C++ - General page
  6. Add a path to the SDK libs to the Linker – General page
  7. Build

Installing the FolderView SDK Sample

  1. Once you have built the sample, copy the FolderViewImpl.dll and FolderViewImpl.propdesc to the same directory
  2. From an elevated cmd window, regsvr32 FolderViewImpl.dll
  3. Restart explorer
  4. Open explorer to Computer
  5. There should be a list item named “FolderView SDK Sample”

Popularity: 1%


Written by chrdavis. Read more great feeds at is source WEBSITE
no comments.
Read more articles on namespace and otherSoftware and extension and Search and Organize and shell and Coding and Programming and vista and search and API and Windows Vista.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> .