Search code examples
winapiopenfiledialog

Getting working directory on OpenFileDialog


When you select a number of files on OpenFileDialog you get the working directory path in a structure member of OPENFILENAME but when you select a single file you get the path to filename in that variable member.

Would there be a possible way to get the path first before looping and counting to check the number of files?


Solution

  • Not quite sure what you mean, OpenFileDialog is a .NET class. Assuming native: you can set the OPENFILENAME.lpfnHook member to a callback function. That gives you notifications like CDN_FILEOK and CDN_FOLDERCHANGE. Gives you a preview of what was selected before the dialog closes and a way to cancel it.