在 CFileDialog (MFC) 中设置文件夹视图 [英] Setting the folder view in a CFileDialog (MFC)

查看:77
本文介绍了在 CFileDialog (MFC) 中设置文件夹视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 CFileDialog(启用了 Vista 风格)中是否有设置文件夹视图的标准方法?我试图让它显示详细信息视图和一些自定义列.

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.

我已经实现了一个 Windows 7 列处理程序,它显示我的应用程序创建的文件的特定于应用程序的信息.但是,为了在资源管理器窗口或通用文件对话框中查看这些自定义列,我必须手动将文件夹视图设置为详细信息,然后选择我想要的特定列.

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.

我研究了各种方法来做到这一点,但没有找到可行的解决方案.shell 属性包似乎存储了列类型和宽度以及视图样式,但其中大部分是二进制的并且没有明显的文档记录.如果我复制包属性,我可以切换视图设置,但这似乎很脆弱.

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.

推荐答案

我认为 Explorer 不会在 Vista/Windows 7 中加载列处理程序.

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

要在 vista 文件对话框中更改视图设置:

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

或者,您可以尝试未公开的方法#2

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

这篇关于在 CFileDialog (MFC) 中设置文件夹视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆