문제

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