zoukankan      html  css  js  c++  java
  • 2019-6-5-WPF-隐藏系统窗口菜单

    title author date CreateTime categories
    WPF 隐藏系统窗口菜单
    lindexi
    2019-06-05 17:26:44 +0800
    2019-06-05 17:17:16 +0800
    WPF

    本文告诉大家如何隐藏系统窗口菜单

    系统的窗口菜单请看下图

    通过在消息里面钩调一些消息的方式,此方法由 黄滨滨 大佬提供

            private IntPtr Hook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
            {
                if (msg == 0x112)
                {
                    var param = wparam.ToInt32();
                    if (param is 0xf093 // 单击打开菜单
                        || param is 0xf100)//键盘打开菜单
                    {
                        handled = true;
                    }
                }
                else if (msg == 0xa4)
                {
                    var param = wparam.ToInt32();
                    if (param == 0x02 // 非图片客户区
                        || param is 0x03)
                    {
                        handled = true;
                    }
                }
    
                return IntPtr.Zero;
            }

    第二个方法是通过设置样式

           public MainWindow()
            {
                InitializeComponent();
    
                SourceInitialized += OnSourceInitialized;
            }
    
            private void OnSourceInitialized(object sender, EventArgs e)
            {
                var windowInteropHelper = new WindowInteropHelper(this);
                var hwnd = windowInteropHelper.Handle;
    
                var windowLong = GetWindowLong(hwnd, GWL_STYLE);
                windowLong &= ~WS_SYSMENU;
    
                SetWindowLongPtr(hwnd, GWL_STYLE, new IntPtr(windowLong));
            }
    
            public const int WS_SYSMENU = 0x00080000;
    
            [DllImport("user32.dll", SetLastError = true)]
            public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
    
            public const int GWL_STYLE = -16;
    
            public static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
            {
                if (Environment.Is64BitProcess)
                {
                    return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
                }
    
                return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToInt32()));
            }
    
            [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
            private static extern int SetWindowLong32(IntPtr hWnd, int nIndex, int dwNewLong);
    
            [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
            private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
    
           
  • 相关阅读:
    在HQL里使用set方式设置的变量
    Nuxt.js 使用vue-social-share.js 插件 分享功能实践
    渗透测试被动信息搜集工具v0.1
    burp工具tips集合
    Go语言之数据类型(二)
    Go语言之数据类型(一)
    Go语言之变量
    Go语言快速入门
    Go语言环境搭建
    [SSH]基础知识——SSH、对称加密、非对称加密、公钥、私钥、中间人攻击
  • 原文地址:https://www.cnblogs.com/lindexi/p/12086306.html
Copyright © 2011-2022 走看看