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;
上一篇:01. 静态库


下一篇:用C#调用Windows API向指定窗口发送按键消息