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;

wpf 删除系统自带右键菜单

上一篇:linux个人常用命令总结(持续更新)


下一篇:如何检查你机器上是否有安装Windows 11所需要的TPM