codeLover
codeLover

Reputation: 3810

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

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.

Upvotes: 0

Views: 2544

Answers (2)

David Heffernan
David Heffernan

Reputation: 613461

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.

Upvotes: 4

Ben Voigt
Ben Voigt

Reputation: 283823

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

Upvotes: 1

Related Questions