Setting the folder view in a CFileDialog (MFC)

蓝咒 提交于 2020-06-27 17:57:07

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/7032421/setting-the-folder-view-in-a-cfiledialog-mfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!