wpf 删除系统自带右键菜单
作者:互联网
/// <summary>
/// 删除系统菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void window_SourceInitialized(object sender, EventArgs e)
{
var window = (Window)sender;
var helper = new WindowInteropHelper(window);
IntPtr windowHandle = helper.Handle; //Get the handle of this window
IntPtr hmenu = GetSystemMenu(windowHandle, 0);
DestroyMenu(hmenu);
hmenu = IntPtr.Zero;
}
[DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
private static extern IntPtr GetSystemMenu(IntPtr hwnd, int revert);
[DllImport("user32.dll", EntryPoint = "GetMenuItemCount")]
private static extern int GetMenuItemCount(IntPtr hmenu);
[DllImport("user32.dll", EntryPoint = "DestroyMenu")]
private static extern bool DestroyMenu(IntPtr hmenu);
private const int MF_BYPOSITION = 0x0400;
private const int MF_DISABLED = 0x0002;
标签:IntPtr,菜单,int,DllImport,private,hmenu,window,右键,wpf 来源: https://blog.51cto.com/shuxiayeshou/2949807