0

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.

codeLover
  • 3,720
  • 10
  • 65
  • 121
  • 1
    See http://stackoverflow.com/questions/31059/how-do-you-configure-an-openfiledialog-to-select-folders which is not C++ but will give you the idea. – Mark Ransom Jan 30 '13 at 04:21

2 Answers2

4

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

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

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720