Related to the answer found here: https://stackoverflow.com/a/29572621/4055837
Using shell32.dll SHOpenWithDialog to prompt the user to select an app to open a file.
Is there a way for me to programmatically detect if the user has cancelled the dialog (either using the cancel button or the [x] to close the dialog? The result that comes back (0x0) is the same result I receive if the user selects an app, which does not allow me to take a different code path if the user changes their mind about opening a file with a specified app.
[edit for clarification] For the scenario I am working with, I need to be able to tell the difference between user cancelling "open with" and user selecting an app in order to direct my application's handling of information related to the file. That app may or may not already be in the registry's OpenWith key.
For files with unusual extensions and files with multiple or custom options, the open behavior may launch open with; for instance, a test file called foo.file that has the OpenWith key and an entry for notepad++.exe still fires the dialog to ask me if I still want to use notepad++.
For many file types my existing checks regarding file and parent folder locking work, but for some extensions/editors, there is no lock being maintained. In those cases, I can detect changes in the file by periodically checking for updates to the file, but that does not help when I need to respond to the user deciding to cancel the "open with" dialog.
[further clarification] The use case calls for supporting the ability for the customer to open a file that may or may not have an associated executable in an executable of their choosing. This is not information that is available until runtime. The application tracks files that should be secured; when an authorized user needs to open a file for editing or execution, the application needs to support the operation required on demand.
- If they change their mind and cancel the Open With, then the file needs to be left in a secure state.
- If they select the executable that they want to open the file with, then the application releases the file to that executable.