Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Tue Aug 26, 2008 8:33 am Post subject: HOWTO: Retrieve selected items in Windows Explorer or a File Open/Save dialog |
|
|
Use the GetSelectedItems() function in the OnSelectionChanged() function to retrieve the list of selected items in Windows Explorer or a File Open/Save dialog.
This can be used in combination with the OnCommonDialogOKButtonClicked() function to determine the item(s) selected in the File Open/Save dialog when the 'OK' button is clicked (or when item is double-clicked or when item is selected and 'Enter' is pressed) :
//.h file
class MyNSEFolder: public CNSEFolder
{
public:
...
...
CPtrList* selectedItems;
virtual void OnSelectionChanged();
virtual void OnCommonDialogOKButtonClicked(CCommonDialogOKButtonClickedEventArgs& e);
...
...
};
////////////////////////////////////////////////////////////////////
//.cpp file
...
...
void MyNSEFolder::OnSelectionChanged()
{
selectedItems = this->GetSelectedItems();
}
void MyNSEFolder::OnCommonDialogOKButtonClicked(CCommonDialogOKButtonClickedEventArgs& e)
{
// 'selectedItems' now contains user-selected item(s)
POSITION p = selectedItems->GetHeadPosition();
CNSEItem* item;
while(p!= NULL)
{
item =(CNSEItem*) selectedItems->GetNext(p);
CString str;
item->GetDisplayName(str);
TRACE(str);
}
} |
|