mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-23 19:49:43 +01:00
Merge branch 'dev' of https://github.com/qianlifeng/Wox.git
This commit is contained in:
@@ -22,6 +22,26 @@ namespace Wox.ShellContext
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetMenuItemCount(IntPtr hMenu);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||
public class MENUITEMINFO
|
||||
{
|
||||
public int cbSize = Marshal.SizeOf(typeof(MENUITEMINFO));
|
||||
public int fMask;
|
||||
public int fType;
|
||||
public int fState;
|
||||
public int wID;
|
||||
public IntPtr hSubMenu;
|
||||
public IntPtr hbmpChecked;
|
||||
public IntPtr hbmpUnchecked;
|
||||
public IntPtr dwItemData;
|
||||
public string dwTypeData;
|
||||
public int cch;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern bool GetMenuItemInfo(HandleRef hMenu, int uItem, bool fByPosition, [In, Out] MENUITEMINFO lpmii);
|
||||
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetMenuString(IntPtr hMenu, uint uIDItem, [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder lpString, int nMaxCount, uint uFlag);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Wox.ShellContext
|
||||
IntPtr desktopPtr;
|
||||
IShellFolder desktop = ShellAPI.GetDesktopFolder(out desktopPtr);
|
||||
|
||||
IntPtr ownerHwnd =IntPtr.Zero;
|
||||
IntPtr ownerHwnd = IntPtr.Zero;
|
||||
IShellFolder Root;
|
||||
string FolderPath = Directory.GetParent(path).FullName;
|
||||
IntPtr Pidl = IntPtr.Zero;
|
||||
@@ -60,20 +60,39 @@ namespace Wox.ShellContext
|
||||
|
||||
IntPtr contextMenu = ShellAPI.CreatePopupMenu();
|
||||
iContextMenu.QueryContextMenu(contextMenu, 0, ShellAPI.CMD_FIRST, ShellAPI.CMD_LAST, CMF.NORMAL | CMF.EXPLORE);
|
||||
|
||||
var menuItemCount = ShellAPI.GetMenuItemCount(contextMenu);
|
||||
for (int k = 0; k < menuItemCount - 1; k++)
|
||||
{
|
||||
StringBuilder menuName = new StringBuilder(0x20);
|
||||
ShellAPI.GetMenuString(contextMenu, i, menuName, 0x20, ShellAPI.MF_BYPOSITION);
|
||||
Debug.WriteLine(menuName.Replace("&",""));
|
||||
ShellAPI.DeleteMenu(contextMenu, i, ShellAPI.MF_BYPOSITION);
|
||||
}
|
||||
ParseMenu(contextMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Marshal.ReleaseComObject(Root);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user