I have a file open/save dialog derived from CFileDialog. Is there anyway to prevent a user from deleting files while browsing using this dialog programmatically? Currently they can right-click and get to the Windows explorer context menu OR just highlight a file and press the Del key. Thanks.
-
Have a look here: http://www.programmersheaven.com/discussion/52429/how-to-disble-the-context-menu-in-the-file-name-list-in-the-open-file – Andrew Truckle Jan 14 '17 at 19:18
-
This is not possible using the standard File Open dialog. I fail to see the rationale for this requirement, too. If you prevent the user from deleting a file from there, they could just fire up *File Explorer*, navigate to the same folder, and delete the file there. – IInspectable Jan 16 '17 at 21:34
-
Thanks @AndrewTruckle. I'm having trouble "...Subclass the file list.." as the link describes. – JDoe1234 Jan 16 '17 at 22:08
-
@IInspectable ... you are correct wrt to _File Explorer_ ; the only difference is user perception. Within our application _everything_ looks like it is from our app. – JDoe1234 Jan 16 '17 at 22:10
-
1In that case, your goal shouldn't be to disable the functionality to delete items, but rather to filter the items that are displayed. – IInspectable Jan 16 '17 at 22:17
1 Answers
Seems to be 2 key issues to resolving this: 1) Finding the handle to the control : Within CFileDialog it contains SHELLDLL_DefView, which contains SysListView32. Spy++ tool helps show this. Override the ListView's WndProc and you can prevent Right-click's
2) Intercepting keyboard commands. Found solution with great explanation (along with more info) at this link: https://www.codeproject.com/Articles/5782/Implementing-a-Read-Only-File-Open-or-File-Save-Co
EDIT: If use the hook function as described above, it does work however get an ASSERT. Alternative is to not use the hook fcn but override the following: CFileDialog::OnInitDone //Handles the WM_NOTIFY CDN_INITDONE message. CFileDialog::OnFolderChange //Handles the WM_NOTIFY CDN_FOLDERCHANGE message.

- 11
- 4
-
And then someone comes along and uses UI Automation. And that puts you back to square one. You are trying to solve the wrong problem, as [previously explained](http://stackoverflow.com/questions/41642751/cfiledialog-prevent-delete#comment70568960_41642751). – IInspectable Jan 18 '17 at 13:10