Setting the folder view in a CFileDialog (MFC)
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 propertie开发者_开发技巧s I can switch the view settings around, but this seems brittle.
Any pointers or other help would be greatly appreciated.
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
精彩评论