Usage of GetOpenFileName() API in VC++ for opening a folder & NOT a file

人盡茶涼 提交于 2019-12-25 02:55:56

问题


BOOL WINAPI GetOpenFileName( Inout LPOPENFILENAME lpofn );

is used for opening a file in a VC++ program, say

C:\Hello\World\abc.txt

. But I want to use this function to select a folder

C:\Hello\World instaed of a file in it.

I guess I need to make some changes to the members of the structure "OPENFILENAME". Can anyone kindly lemme know how do I achieve this in a VC++ program. Thanks in advance.


回答1:


GetOpenFileName does not support folder selection at all.

Your options are:

  • SHBrowseForFolder which is available on Windows 2000 and later, but looks a bit ugly.
  • IFileDialog which is the platform native folder chooser, but only available on Vista or later. To make the dialog behave as a folder picker, pass FOS_PICKFOLDERS to SetOptions.

In my opinion the best result for the user is to use IFileDialog where available, but fall back to SHBrowseForFolder for older operating systems.




回答2:


There's ShBrowseForFolder. Plenty of C++ examples around if you search.



来源:https://stackoverflow.com/questions/14596493/usage-of-getopenfilename-api-in-vc-for-opening-a-folder-not-a-file

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