Date: | October 1, 2004 / year-entry #355 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20041001-00/?p=37683 |
Comments: | 5 |
Summary: | There is a small improvement that can be made to to the program we wrote last time. It involves taking advantage of the last parameter to the IContextMenu::QueryContextMenu method: CMF_DEFAULTONLY This flag is set when the user is activating the default action, typically by double-clicking. This flag provides a hint for the shortcut menu extension... |
There is a small improvement that can be made to to the program we wrote last time. It involves taking advantage of the last parameter to the IContextMenu::QueryContextMenu method:
As the text from MSDN indicates, this flag is a hint to the IContextMenu implementation that it should worry only about the default command. void OnContextMenu(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos) { IContextMenu *pcm; if (SUCCEEDED(GetUIObjectOfFile(hwnd, L"C:\\Windows\\clock.avi", IID_IContextMenu, (void**)&pcm))) { HMENU hmenu = CreatePopupMenu(); if (hmenu) { if (SUCCEEDED(pcm->QueryContextMenu(hmenu, 0, SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST, CMF_DEFAULTONLY))) { UINT id = GetMenuDefaultItem(hmenu, FALSE, 0); if (id != (UINT)-1) { CMINVOKECOMMANDINFO info = { 0 }; info.cbSize = sizeof(info); info.hwnd = hwnd; info.lpVerb = MAKEINTRESOURCEA(id - SCRATCH_QCM_FIRST); pcm->InvokeCommand(&info); } } DestroyMenu(hmenu); } pcm->Release(); } }
With this change on my machine, the time taken by the call to
IContextMenu::QueryContextMenu dropped from 100ms to 50ms.
Your mileage may vary.
It depends on how many context menu extensions you have and
how well they respect the
(And this exercise highlights how important it is that people
who implement the |
Comments (5)
Comments are closed. |
You the man
Interesting stuff. I wonder, does this also affect the performance of ShellExecute (with default verb), or has that function been optimized to not even build the context menu?
By the way, how big does Mt St Helens have to blow before you can see it?
IContextMenu のホスト方法 – Shell
I’ve been following in awe the series of posts (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) by Raymond Chen about