Вопрос

I'd like to allow users of my Windows game to use a dialog box to select a folder or a file. I can currently do one or the other using SHBrowseForFolder or GetOpenFileName, but not both options from within the same dialog. Is this possible? (Reason being I'm porting a Mac game where this is possible.)

Это было полезно?

Решение

When you bring up the file dialog, give it a default filename such as "Entire folder" and turn off the flag that requires the file to exist before enabling the OK button. When the dialog returns, check the filename to see if it matches the special string "Entire folder" and treat it accordingly.

Based on my answer to another question: How do you configure an OpenFileDialog to select folders?

Другие советы

If you set OFN_NOVALIDATE in the Flags member of the OPENFILENAME structure, typing a folder name without a '\' at the end, and pressing Enter (or Open), will send the CDN_FILEOK notification to the hook procedure, not the CDN_FOLDERCHANGE notification.

From there, you may do whatever you want with the folder path. To me, this is a bug, but it might help you.

To the very best of my knowledge, the common dialogs cannot be operated in a mode where you can select either folder or file from the same dialog.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top