BUG: Using Windows Classic Mode in Windows Explorer Returns Incorrect Value for SelectedItems (819499)



The information in this article applies to:

  • Microsoft Windows 2000

SYMPTOMS

When you set Windows Explorer to display folders in the Windows Classic mode, the SelectedItems method of the IShellFolderViewDual interface returns an incorrect set of FolderItems .

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Open a text editor such as Notepad, paste the following code into a new file, and then save the file as Sample.cpp:
    #include <Windows.h>
    #include <TChar.h>
    #import <SHDocVw.dll>
    #import <Shell32.dll>
    #include <iostream>
    using namespace std;
    
    int _tmain(int argc, TCHAR ** argv)
    {
        CoInitialize(0);
        try
        {    
            SHDocVw::IShellWindowsPtr sw(__uuidof(SHDocVw::ShellWindows));
            for (long i = 0; i < sw->Count; ++i)
            {
                if (SHDocVw::IWebBrowser2Ptr ie = sw->Item(i))
                {
                    cout << _com_util::ConvertBSTRToString(ie->LocationURL) << endl;
                    if (Shell32::IShellFolderViewDualPtr view = ie->Document)
                    {
                       cout << view->SelectedItems()->Count << _T(" selected item(s)") << endl;
                    }
                }
            }
        }
        catch (_com_error const & e)
        {
            cout << e.ErrorMessage() << endl;
        }
        CoUninitialize();
        return 0;
    }
  2. At a command prompt, compile the file by running the following command: cl /EHsc Sample.cpp
  3. Close all the Windows Explorer windows that are currently open.
  4. Right-click Start, and then click Explore to open a Windows Explorer window.
  5. On the Tools menu, click Folder Options
  6. On theGeneral tab, select the Use Windows classic folders option under Web View, and then click OK.
  7. Select a folder that contains many items. In the right pane, select some of the items in this folder.
  8. At a command prompt, run the Sample.exe executable (that you generated in step 2).

    The output displays the result of the Count property of the FolderItems instance that is returned by the SelectedItems method of IShellFolderViewDual interface.

    You expect the output to be the number of items that you have selected in the folder in Windows Explorer from the earlier step. However, the output contains the number of all the items in the folder that was selected in Windows Explorer.
  9. When Windows Explorer is inWeb view mode, the folder items that are returned by SelectedItems is correctly set to the FolderItem instances that are selected.

    To verify the previous statement in Windows Explorer, on the Tools menu, click Folder options.
  10. On the General tab, click the Enable Web content on my desktop option under Web View, and then click OK to close the dialog box.
  11. At a command prompt, run Sample.exe (generated in step 2).

    The output displays the result of the Count property of the FolderItems instance that is returned by the SelectedItems method of IShellFolderViewDual interface.

    The output is, as expected, the number of items that you had selected in the folder.
Alternatively, you can use the FocusedItem method of the IShellFolderViewDual interface to replace the incorrect functionality of the SelectedItems method. The FocusedItem method returns the currently selected item in the folder and restricts your application to a single folder selection in Windows Explorer.

REFERENCES

For additional information about the Shell programming guide, see the following MSDN documentation:

Modification Type:MinorLast Reviewed:10/25/2005
Keywords:kbHotfixServer kbQFE kbshell kbBug KB819499 kbAudDeveloper