2

Is there a standard way to set the folder view in a CFileDialog (Vista-style enabled)? I'm trying to get it to show Details view and some custom columns.

I've implemented a Windows 7 column handler that displays app-specific info for files created by my app. However, in order to view these custom columns in an Explorer window or a common file dialog, I have to manually set the folder view to Details then select the specific columns I want.

This works fine, but the goal is for the file selector in the app to show these columns in Details view automatically, if only until the user changes the view style.

I've investigated various ways to do this and haven't found a workable solution. The shell property bags seem to store the column types and widths as well as the view style, but much of it is binary and not apparently documented. If I copy the bag properties I can switch the view settings around, but this seems brittle.

Any pointers or other help would be greatly appreciated.

cue
  • 41
  • 4

1 Answers1

2

I don't think Explorer loads column handlers in Vista/Windows 7.

To change view settings in the vista file dialog:

Check OS version (needs Vista or higher)    
Not sure which event is raised on startup, OnFolderChange maybe?
assuming OnFolderChange is raised, override CFileDialog::OnFolderChange:
call GetIFileSaveDialog/GetIFileOpenDialog to get IFileDialog
//begin undocumented behavior 
QI for IServiceProvider from IFileDialog
QS for SID_SFolderView with IID_IFolderView2
call IFolderView2::SetViewModeAndIconSize
//end undocumented behavior
clean up COM interfaces

Alternatively you can try undocumented method #2

//begin undocumented behavior 
QI for IServiceProvider from IFileDialog
QS for SID_STopLevelBrowser with IID_IShellBrowser
call IShellBrowser::QueryActiveShellView to get IShellView
QI IFolderView2 from IShellView
call IFolderView2::SetViewModeAndIconSize
//end undocumented behavior
clean up COM interfaces
Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • I called it a column handler, but it uses the property system COM interfaces to handle the showing the custom columns and the data that goes into them. That works fine in Vista and 7 (on XP, I'd need to implement the prior IColumnProvider, but that's another story). Thanks, I'll investigate that approach. – cue Aug 12 '11 at 13:04
  • I wish I had enough karma to up-vote you. The end result used the IFolderView2 from IFileDialog -> IServiceProvider to change the view to Details mode. Then using the IColumnManager from IServiceProvider -> IShellBrowser -> IShellView I was able to set the columns using the property store prop keys for my custom columns. Thanks much. – cue Aug 12 '11 at 15:09