首页 > Windows开发 > 详细

wpf 删除系统自带右键菜单

时间:2021-06-26 17:05:50      阅读:17      评论:0      收藏:0      [点我收藏+]
/// <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 删除系统自带右键菜单

原文:https://blog.51cto.com/shuxiayeshou/2949807

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!