ISvItemCm_fnQueryContextMenu load menu from .rc: Patch writing problems

Tobias Burnus burnus at net-b.de
Fri Jun 10 12:06:17 CDT 2005


Hello,

I'd like to modify ISvItemCm_fnQueryContextMenu 
(shell32/shv_item_cmenu.c) in a way that it loads the strings from the 
.rc file.

But I have some trouble. I modified the shell32_En.rc to look like the 
created context menu, but which puzzles me is that there are two times 
the same ID: FCIDM_SHVIEW_OPEN for "&Select" and for "&Open" which are 
shown at the same time!
Depending on context (i.e. flags), I need to remove the "&Select" and 
switch the order of Explore and Open. But somehow the code below does 
not work (I think MF_BYPOSITION might cause the problem, but since 
Select and Open have the same id, I cannot use MF_BYCOMMAND).
Any pointer what I'm doing wrong?

Tobias

shell32_En.rc
===================================================================
MENU_SHV_FILE MENU DISCARDABLE
 BEGIN
        POPUP ""
        BEGIN
+         MENUITEM "&Select",           FCIDM_SHVIEW_OPEN
          MENUITEM "E&xplore",          FCIDM_SHVIEW_EXPLORE
          MENUITEM "&Open",             FCIDM_SHVIEW_OPEN
          MENUITEM SEPARATOR
          MENUITEM "C&ut",              FCIDM_SHVIEW_CUT
          MENUITEM "&Copy",             FCIDM_SHVIEW_COPY
          MENUITEM SEPARATOR
-         MENUITEM "Create &Link",      FCIDM_SHVIEW_CREATELINK
+/*       MENUITEM "Create &Link",      FCIDM_SHVIEW_CREATELINK*/
          MENUITEM "&Delete",           FCIDM_SHVIEW_DELETE
          MENUITEM "&Rename",           FCIDM_SHVIEW_RENAME
-         MENUITEM SEPARATOR
-         MENUITEM "&Properties",       FCIDM_SHVIEW_PROPERTIES
+/*       MENUITEM SEPARATOR
+         MENUITEM "&Properties",       FCIDM_SHVIEW_PROPERTIES*/
        END
 END
===================================================================

Index: shv_item_cmenu.c (deleted lines omitted in the 
ISvItemCm_fnQueryContextMenu function)
===================================================================
@@ -36,6 +36,7 @@

 #include "shell32_main.h"
 #include "shellfolder.h"
+#include "shresdef.h"

 WINE_DEFAULT_DEBUG_CHANNEL(shell);

@@ -208,57 +209,127 @@
        InsertMenuItemA( hmenu, indexMenu, fByPosition, &mii);
 }

+
 /**************************************************************************
 * ISvItemCm_fnQueryContextMenu()
-* FIXME: load menu MENU_SHV_FILE out of resources instead if creating
-*               each menu item by calling _InsertMenuItem()
 */
 static HRESULT WINAPI ISvItemCm_fnQueryContextMenu(
        IContextMenu2 *iface,
-       HMENU hmenu,
+       HMENU hMenu,
        UINT indexMenu,
        UINT idCmdFirst,
        UINT idCmdLast,
        UINT uFlags)
 {
+        const DWORD buflen = 80;
+        WCHAR szString[buflen];
+       HMENU       hMyMenu;
+       HRESULT hr;
+        UINT        idMax;
+       MENUITEMINFOW   mii;
+
+       ItemCmImpl *This = (ItemCmImpl *)iface;
+
+       TRACE("(%p)->(hMenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x 
flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLa
st, uFlags);
+
+       if (idCmdFirst != 0)
+         FIXME("We should use idCmdFirst=%d and idCmdLast=%d for 
command ids\n", idCmdFirst, idCmdLast);
+
+       if(!(CMF_DEFAULTONLY & uFlags) && This->cidl>0)
+       {
+               hMyMenu = LoadMenuA(shell32_hInstance, "MENU_SHV_FILE");
+
+             if((uFlags || CMF_EXPLORE)) { /* Remove "&Select" */
+                   RemoveMenu(hMyMenu, 0, MF_BYPOSITION);
+             }
+             if(!This->bAllValues) { / * Change order of OPEN and 
EXPLORE */
+                 GetMenuItemInfoW(hMyMenu, 2, TRUE, &mii);
+                 DeleteMenu(hMyMenu, 2, MF_BYPOSITION);
+                 InsertMenuItemW(hMyMenu,  1, TRUE, &mii);
+                }
+
+               if(ISvItemCm_CanRenameItems(This) == MFS_DISABLED) {
+                   EnableMenuItem(hMyMenu, FCIDM_SHVIEW_RENAME, 
MFS_DISABLED);
+               }
+
+               idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), 
indexMenu,
+                                  idCmdFirst, idCmdLast, 
MM_SUBMENUSHAVEIDS);
+               hr =  MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 
idMax-idCmdFirst+1);
+               SetMenuDefaultItem(hMenu, 0, MF_BYPOSITION);
+
+               DestroyMenu(hMyMenu);
+       }
+        else {
+               return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
+        }
+       TRACE("(%p)->returning 0x%lx\n",This,hr);
+       return hr;
}



More information about the wine-devel mailing list