mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Implement ShellContextMenu [WIP]
This commit is contained in:
@@ -22,6 +22,26 @@ namespace Wox.ShellContext
|
|||||||
[DllImport("user32.dll")]
|
[DllImport("user32.dll")]
|
||||||
public static extern int GetMenuItemCount(IntPtr hMenu);
|
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")]
|
[DllImport("user32.dll")]
|
||||||
public static extern int GetMenuString(IntPtr hMenu, uint uIDItem, [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder lpString, int nMaxCount, uint uFlag);
|
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;
|
IntPtr desktopPtr;
|
||||||
IShellFolder desktop = ShellAPI.GetDesktopFolder(out desktopPtr);
|
IShellFolder desktop = ShellAPI.GetDesktopFolder(out desktopPtr);
|
||||||
|
|
||||||
IntPtr ownerHwnd =IntPtr.Zero;
|
IntPtr ownerHwnd = IntPtr.Zero;
|
||||||
IShellFolder Root;
|
IShellFolder Root;
|
||||||
string FolderPath = Directory.GetParent(path).FullName;
|
string FolderPath = Directory.GetParent(path).FullName;
|
||||||
IntPtr Pidl = IntPtr.Zero;
|
IntPtr Pidl = IntPtr.Zero;
|
||||||
@@ -60,20 +60,39 @@ namespace Wox.ShellContext
|
|||||||
|
|
||||||
IntPtr contextMenu = ShellAPI.CreatePopupMenu();
|
IntPtr contextMenu = ShellAPI.CreatePopupMenu();
|
||||||
iContextMenu.QueryContextMenu(contextMenu, 0, ShellAPI.CMD_FIRST, ShellAPI.CMD_LAST, CMF.NORMAL | CMF.EXPLORE);
|
iContextMenu.QueryContextMenu(contextMenu, 0, ShellAPI.CMD_FIRST, ShellAPI.CMD_LAST, CMF.NORMAL | CMF.EXPLORE);
|
||||||
|
ParseMenu(contextMenu);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Marshal.ReleaseComObject(Root);
|
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