1
votes

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.

1
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
Thanks @AndrewTruckle. I'm having trouble "...Subclass the file list.." as the link describes. - JDoe1234
@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
In that case, your goal shouldn't be to disable the functionality to delete items, but rather to filter the items that are displayed. - IInspectable

1 Answers

0
votes

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.