예제 #1
0
        private void ParseMenu(IntPtr contextMenu)
        {
            var menuItemCount = ShellAPI.GetMenuItemCount(contextMenu);

            for (uint k = 0; k < menuItemCount - 1; k++)
            {
                StringBuilder menuName = new StringBuilder(320);
                ShellAPI.GetMenuString(contextMenu, k, menuName, 320, ShellAPI.MF_BYPOSITION);
                Debug.WriteLine(menuName.Replace("&", ""));

                //https://msdn.microsoft.com/en-us/library/windows/desktop/ms647578(v=vs.85).aspx
                ShellAPI.MENUITEMINFO menuiteminfo_t;
                int MIIM_SUBMENU = 0x00000004;
                int MIIM_STRING  = 0x00000040;
                int MIIM_FTYPE   = 0x00000100;
                menuiteminfo_t            = new ShellAPI.MENUITEMINFO();
                menuiteminfo_t.fMask      = MIIM_SUBMENU | MIIM_STRING | MIIM_FTYPE;
                menuiteminfo_t.dwTypeData = new string('\0', 320);
                menuiteminfo_t.cch        = menuiteminfo_t.dwTypeData.Length - 1;
                bool result = ShellAPI.GetMenuItemInfo(new HandleRef(null, contextMenu), (int)k, true, menuiteminfo_t);
                if (menuiteminfo_t.hSubMenu != IntPtr.Zero)
                {
                    ParseMenu(menuiteminfo_t.hSubMenu);
                }
                ShellAPI.DeleteMenu(contextMenu, k, ShellAPI.MF_BYPOSITION);
            }
        }
예제 #2
0
        private void ParseMenu(IntPtr contextMenu)
        {
            var menuItemCount = ShellAPI.GetMenuItemCount(contextMenu);
            for (uint k = 0; k < menuItemCount - 1; k++)
            {
                StringBuilder menuName = new StringBuilder(320);
                ShellAPI.GetMenuString(contextMenu, k, menuName, 320, ShellAPI.MF_BYPOSITION);
                Debug.WriteLine(menuName.Replace("&", ""));

                //https://msdn.microsoft.com/en-us/library/windows/desktop/ms647578(v=vs.85).aspx
                ShellAPI.MENUITEMINFO menuiteminfo_t;
                int MIIM_SUBMENU = 0x00000004;
                int MIIM_STRING = 0x00000040;
                int MIIM_FTYPE = 0x00000100;
                menuiteminfo_t = new ShellAPI.MENUITEMINFO();
                menuiteminfo_t.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_FTYPE;
                menuiteminfo_t.dwTypeData = new string('\0', 320);
                menuiteminfo_t.cch = menuiteminfo_t.dwTypeData.Length - 1;
                bool result = ShellAPI.GetMenuItemInfo(new HandleRef(null, contextMenu), (int)k, true, menuiteminfo_t);
                if (menuiteminfo_t.hSubMenu != IntPtr.Zero)
                {
                    ParseMenu(menuiteminfo_t.hSubMenu);
                }
                ShellAPI.DeleteMenu(contextMenu, k, ShellAPI.MF_BYPOSITION);
            }
        }