3

I'm writing some code will automate selection of Window Explorer(explorer.exe) items. And I found two methods that might help:

HRESULT SelectItem(
  [in]  VARIANT *pvfi,
  [in]  int dwFlags
);
// from http://msdn.microsoft.com/en-us/library/windows/desktop/dd894079(v=vs.85).aspx

HRESULT SelectItemRelative(
  [in]  int iRelative
);
// from http://msdn.microsoft.com/en-us/library/windows/desktop/bb774966(v=vs.85).aspx

I've tried SelectItemRelative and it works perfectly; next item in explorer is selected when I pass 1 as argument. The method is self-explanatory

Now, I don't quite get SelectItem, it takes a VARIANT and an int. According to MSDN, the int flag tells the method what kind of selection to make, and that's all, no explanation on what VARIANT is.

What should I pass for VARIANT *pvfi?

tom91136
  • 8,662
  • 12
  • 58
  • 74

2 Answers2

2

For VARIANT you may pass LPCITEMIDLIST of the item.

user2120666
  • 579
  • 1
  • 4
  • 16
2

IShellFolderViewDual is a dual to the (long gone IIRC) IShellFolderView. Some vestigial documentation remains. Someone has been a fan of quantum physics, it seems.

The variant should carry a VT_UNKNOWN pointing to the FolderItem instance of the item you wish to change the selection of. Then, the selection flags are as follows:

  • 0 (SVSI_DESELECT) deselect
  • 1 (SVSI_SELECT) select
  • 3 (SVSI_EDIT) put the item in edit mode
  • 4 (SVSI_DESELECTOTHERS) deselect all bu the specified item
  • 8 (SVSI_ENSUREVISIBLE) ensure that the item is visible in the view (scrollthe view)
  • 16 (SVSI_FOCUSED) give the item the focus
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313