Date: | September 24, 2004 / year-entry #348 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20040924-00/?p=37753 |
Comments: | 6 |
Summary: | Another of the bugs you may have noticed in our first attempt at displaying the context menu to the user is that the Delete command doesn't alter its behavior depending on whether you hold the shift key. Recall that holding the shift key changes the behavior of the Delete command, causing it to delete a... |
Another of the bugs you may have noticed in our first attempt at displaying the context menu to the user is that the Delete command doesn't alter its behavior depending on whether you hold the shift key. Recall that holding the shift key changes the behavior of the Delete command, causing it to delete a file immediately instead of moving it to the Recycle Bin. But in our sample program, it always offers to move the file to the Recycle Bin, even if you have the shift key down. (You can see the difference in the wording of the dialog and in the icon. If the operation is to move the item into the Recycle Bin, you get a Recycle Bin icon and the text asks you to confirm sending the item to the Recycle Bin. If the operation will delete the item permanently, then you get an icon that shows a file and a folder fading away and the text asks you to confirm deleting the item.) To convey this information to the context menu, you need to pass the key states in the CMINVOKECOMMANDINFOEX structure. CMINVOKECOMMANDINFOEX info = { 0 }; info.cbSize = sizeof(info); info.fMask = CMIC_MASK_UNICODE | CMIC_MASK_PTINVOKE; if (GetKeyState(VK_CONTROL) < 0) { info.fMask |= CMIC_MASK_CONTROL_DOWN; } if (GetKeyState(VK_SHIFT) < 0) { info.fMask |= CMIC_MASK_SHIFT_DOWN; } Make this change and observe that the dialogs you get from the Delete option now respect your shift key state. Warning: Before playing with this, make sure that you have enabled delete confirmation warnings or you will end up deleting your clock.avi file for real! If you want to play around with the Delete option, you may want to tweak the program so it operates on a file you don't mind losing. Exercise: There's another place where key context influences the context menu, namely the convention that holding the shift key while right-clicking enables "extended verbs". These are verbs that are lesser-used and therefore do not appear on the conventional context menu to avoid creating clutter. For homework, incorporate the extended verb convention into the sample program. [Sorry today's entries are late. Had problems connecting to the blog server.] |
Comments (6)
Comments are closed. |
if (GetKeyState(VK_SHIFT) < 0)
{
Call QueryContextMenu with CMF_EXTENDEDVERBS
}
Nice set of articles that are long over due! I have a question that a bit more along the lines of the first article that has to do with the verb to invoke.
I have found that depending on the IShellFolder executing the "verb" string can lead to results that are different than if you execute the same through explorer. I can’t recall the exact example but I found that if I take the requested "verb" to execute and compare it to what I get back from GetCommandString and if equal (i.e. it is a common verb) I then instead of setting lpVerb to the "verb" I use MakeIntResource to set lpVerb I get consistent results with Explorer. Can you elaborate on that more?
The only note in my code I put was this:
{The result of using the ‘verb’ string and the MakeIntResource is different expecially on system folders. This forces it to use MakeIntResource if it can}
IContextMenu のホスト方法 – Shell
Because Alt already has other meaning.