将 MenuItem 添加到现有的 WPF header 菜单
Adding MenuItem to the allready existing WPF header Menu
What at the moment is, What i want
我想将 MenuItem 添加到单击应用程序图标时打开的现有菜单。
感谢您的帮助。
可以使用互操作来完成 Win32 调用...首先覆盖 Window 的 SourceInitialized 方法并添加以下内容:
public const uint MyMenuItemID = 0x0555;
private const uint MF_BYCOMMAND = 0x00000000;
private const uint MF_BYPOSITION = 0x00000400;
[DllImport ("user32.dll")]
private static extern IntPtr GetSystemMenu (IntPtr hWnd, bool bRevert);
[DllImport ("user32.dll")]
private static extern bool InsertMenu (IntPtr hMenu, uint uPosition, uint uFlags, uint uIDNewItem, string lpNewItem);
private void Window_SourceInitialized (object sender, EventArgs e)
{
HwndSource source = PresentationSource.FromVisual (this) as HwndSource;
if (source != null) {
IntPtr hMenu = GetSystemMenu (source.Handle, false);
InsertMenu (hMenu, 5, MF_BYPOSITION, MyMenuItemID, "my own MenuItem");
}
}
What at the moment is, What i want
我想将 MenuItem 添加到单击应用程序图标时打开的现有菜单。
感谢您的帮助。
可以使用互操作来完成 Win32 调用...首先覆盖 Window 的 SourceInitialized 方法并添加以下内容:
public const uint MyMenuItemID = 0x0555;
private const uint MF_BYCOMMAND = 0x00000000;
private const uint MF_BYPOSITION = 0x00000400;
[DllImport ("user32.dll")]
private static extern IntPtr GetSystemMenu (IntPtr hWnd, bool bRevert);
[DllImport ("user32.dll")]
private static extern bool InsertMenu (IntPtr hMenu, uint uPosition, uint uFlags, uint uIDNewItem, string lpNewItem);
private void Window_SourceInitialized (object sender, EventArgs e)
{
HwndSource source = PresentationSource.FromVisual (this) as HwndSource;
if (source != null) {
IntPtr hMenu = GetSystemMenu (source.Handle, false);
InsertMenu (hMenu, 5, MF_BYPOSITION, MyMenuItemID, "my own MenuItem");
}
}