问题
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, passFOS_PICKFOLDERS
toSetOptions
.
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