Search code examples
mfcdelete-filecfiledialog

CFileDialog - prevent delete


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.


Solution

  • 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.