Home Dashboard Directory Help
Search

CMFCShellListCtrl::OnContextMenu 'Delete' context menu handler does not work in Windows 7 by avogler


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 792003
Opened: 6/30/2013 7:22:36 PM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

I have an MFC (VS 2010) application that uses both CMFCShellTreeCtrl and CMFCShellListCtrl objects in an Explorer-like implementation. After testing on Windows XP and Windows 7, I've discovered that CMFCShellListCtrl::OnContextMenu does not handle the 'Delete' operation in Windows 7. The HRESULT value is -2144927744 after the InvokeCommand call in afxshelllistctrl.cpp on line 994. The context menu does appear and all other context menu operations work - except the Delete handler. The Delete operation does work in the CMFCShellTreeCtrl object. Here is a summary:

CMFCShellListCtrl:
     hr = -2144927744 always ('Delete File' user prompt never appears on Windows 7)

CMFCShellTreeCtrl:
     hr = S_OK when 'Yes' is selected on 'Delete Folder' user prompt
     hr = -2144927744 when 'No' is selected on 'Delete Folder' user prompt

When debugging, the values for the CMINVOKECOMMANDINFO object are setup the same for both the shell list and tree controls. Even the idCmd value (18) is the same in both instances.

This HRESULT value seems to equate to 0x80270000: COPYENGINE_E_USER_CANCELLED (User canceled the current action), although their certainly was no UI action that was displayed (i.e. Delete File message prompt).

All of this works correctly in Windows XP, but Delete does not get invoked on the CMFCShellListCtrl object in Windows 7.

I also get the exact same results when using a Visual Studio sample project.

I have also tried using the ShellExView (by Nir Sofer) tool to view and manage all installed shell extensions, but after disabling most of the extensions, I could not isolate the problem any further.

More observations noted:
1) Running the app as Administrator does not fix the problem
2) Problem is observed on multiple Windows 7 machines (corporate and home computers)
3) All other context menu handlers do work (Open, Edit, Properties, etc.) - except the Delete handler
4) The Delete handler does work in CMFCShellTreeCtrl
Details
Sign in to post a comment.
Posted by Microsoft on 7/18/2013 at 1:27 PM
Hello,

Thanks for the report. This bug has been fixed in MFC for Visual Studio 2013 RTM.

Pat Brenner
Visual C++ Libraries Development
Posted by avogler on 7/16/2013 at 4:01 PM
PROBLEM SOLVED (07/16/2013)

CMFCShellListCtrl::OnContextMenu (afxshelllistctrl.cpp) on line 986 contains the following line:
    cmi.hwnd = (HWND) GetParent();

This line should be:
    cmi.hwnd = GetParent()->GetSafeHwnd();

Even though the casting of a CWnd* to an HWND yields an identical numerical value, for some unknown reason however, it yields different results between Windows XP (where it works) and Windows 7 (where it doesn't). Using GetSafeHwnd() fixes the problem so that the 'Delete File' confirmation dialog box now is displayed. It also works on Windows XP.

Better yet, this MFC file should have had the same implementation as in CMFCShellTreeCtrl::OnShowContextMenu (afxshelltreectrl.cpp):

    HWND hwndParent = GetParent()->GetSafeHwnd();
    ...
    HRESULT hr = psfFolder->GetUIObjectOf(hwndParent, 1, (LPCITEMIDLIST*)&pInfo->pidlRel, IID_IContextMenu, NULL, (LPVOID*)&pcm);
    ...
    cmi.hwnd = hwndParent;

Not sure if this has been fixed in the MFC VS2012 library. Unfortunately, to correct this problem with MFC VS2010, you have to derive a class from CMFCShellListCtrl and override OnContextMenu with the corrected code. Also have to work around the afxShellManager code by using theApp.GetShellManager() instead.

I'm surprised no one else has discovered this problem. Either there are few MFC developers or CMFCShellListCtrl has not been used/tested on Windows 7. I hope Microsoft discovers this post and uses it to correct the next MFC library implementation.
Posted by Microsoft on 6/30/2013 at 8:12 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 6/30/2013 at 7:55 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by avogler on 7/15/2013 at 3:31 PM
CMFCShellListCtrl::OnContextMenu 'Delete' context menu handler can be made to work by unchecking the 'Display delete confirmation dialog' option in the Recycle Bin Properties on Windows 7, but this defeats the purpose of having a user prompt before deleting a file. It also does not explain why the 'Delete' context menu handler works correctly for folders using CMFCShellTreeCtrl even without this change.