c#中通过截获windows消息禁止改变窗体大小

2023-05-16

 private const int WM_SYSCOMMAND = 0x112;
        private const int MF_REMOVE = 0x1000;
        private const int SC_RESTORE = 0xF120;     //还原   
        private const int SC_MOVE = 0xF010;   //移动   
        private const int SC_SIZE = 0xF000;   //大小   
        private const int SC_SIZEChange = 0xF002;   //大小   
        private const int SC_MINIMIZE = 0xF020;   //最小化   
        private const int SC_MAXIMIZE = 0xF030;   //最大化   
        private const int SC_CLOSE = 0xF060;   //关闭     
        [DllImport("USER32.DLL")]
        public static extern int GetSystemMenu(int hwnd, int bRevert);
        [DllImport("USER32.DLL")]
        public static extern int RemoveMenu(int hMenu, int nPosition, int wFlags);

        private void SetCloseMenu()
        {
            int hMenu = GetSystemMenu(this.Handle.ToInt32(), 0);//移除关闭按钮
            RemoveMenu(hMenu, SC_CLOSE, MF_REMOVE);
        }

 

protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                
                case WM_SYSCOMMAND:
                    switch (m.WParam.ToInt32())
                    {
                        case SC_MINIMIZE:
                            base.WndProc(ref m);
                            //捕获最小化消息
                            break;
                        case SC_RESTORE:
                            base.WndProc(ref m);
                            //捕获还原消息
                            break;
                        case SC_MAXIMIZE:
                            this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
                            this.Height = this.panel1.Height * 20;
                            //base.WndProc(ref m);
                            //捕获最大化消息
                            break;
                        case SC_SIZEChange:

                            this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
                            this.Height = this.panel1.Height * 20;
                            break;
                        case 61443:

                            this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
                            this.Height = this.panel1.Height * 20;
                            break;
                        case 61446:

                            this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
                            this.Height = this.panel1.Height * 20;
                            break;
                        case 61441:

                            this.Width = this.panel1.Width + this.textBox_Receiv.Width + 100;
                            this.Height = this.panel1.Height * 20;
                            break;
                        default:
                            base.WndProc(ref m);
                            break;
                    }
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

c#中通过截获windows消息禁止改变窗体大小 的相关文章

随机推荐

  • C# Socket服务器及多客户端连接应用例程

    服务端代码 控制台示例 static List lt Socket gt Sockets 61 new List lt Socket gt static void Main string args int port 61 10 byte b
  • C#Socket文件传输(发送与接收代码)

    原文链接 xff1a http www cnblogs com reynoldchan p 3762014 html 这里是发送的代码 xff1a SendVarData是转码后发送函数 1 lt summary gt 2 发送文件 3 l
  • C# Socket服务端与客户端通信(包含大文件的断点传输)

    步骤 xff1a 一 服务端的建立 1 服务端的项目建立以及页面布局 2 各功能按键的事件代码 1 xff09 传输类型说明以及全局变量 2 xff09 Socket通信服务端具体步骤 xff1a xff08 1 xff09 建立一个Soc
  • C# Socket案例(服务端与客户端)

    本文链接 xff1a https blog csdn net qq 42203978 article details 80520299 服务端完整代码 using System using System Net using System N
  • C#中的Socket编程-TCP客户端

    TCP客户端 using System using System Collections Generic using System Linq using System Net using System Net Sockets using S
  • 最小花费(图论算法)

    Description 在n个人中 xff0c 某些人的银行账号之间可以互相转账 这些人之间转账的手续费各不相同 给定这些人之间转账时需要从转账金额里扣除百分之几的手续费 xff0c 请问A最少需要多少钱使得转账后B收到100元 Input
  • C#获取本机IP地址字符串

    1 using System Net 2 using System Net Sockets 3 4 lt summary gt 5 获取本机IP地址 6 lt summary gt 7 lt returns gt 本机IP地址 lt ret
  • C#中Socket通信用法实例详解

    本文实例讲述了C 中Socket通信用法 分享给大家供大家参考 具体如下 xff1a 一 UDP方式 xff1a 服务器端代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
  • 内存溢出问题分析

    System OutOfMemoryException 大多是数据处理的过程中 xff0c 对内存资源的管控太过于粗放 建议对于非托管资源的使用不要过于随意 内存分配的时候使用内存池的模式 xff0c 避免内存泄露和内存碎片 你的指针可能成
  • C# GC 垃圾回收机制原理

    转载参照自以下文章 xff1a http www cnblogs com fdyang p 3456258 html c 销毁资源和释放内存 https www cnblogs com Jessy articles 2552839 html
  • c++中 结构体和类的区别

    区别 xff1a 结构是一种用关键字struct声明的自定义数据类型 与类相似 xff0c 也可以包含构造函数 xff0c 常数 xff0c 字段 xff0c 方法 xff0c 属性 xff0c 索引器 xff0c 运算符和嵌套类型等 xf
  • 结构体和类的区别

    结构体和类的区别 xff1a 在做一个项目时 xff0c 使用了较多的结构体 xff0c 并且存在一些结构体的嵌套 xff0c 即某结构体成员集合包含另一个结构体等 xff0c 总是出现一些奇怪的错误 xff0c 才终于下决心好好分析一下到
  • C++程序内存分配方式(堆与栈)

    一 内存布局 1 栈区 xff08 stack xff09 xff1a 由编译器自动分配释放 xff0c 存放函数的参数值 xff0c 局部变量值等 xff0c 其操作方法类似数据结构中的栈 2 堆区 xff08 heap xff09 xf
  • 值引用和引用问题分析

    在c 43 43 中 xff0c 声明一个全局变量A a xff0c 然后在一个局部函数中创建类型A c赋值给a xff0c 对于值类型 xff0c 如结构体等 xff0c 是在栈中分配内存c xff0c 然后拷贝其内存所有值给a xff0
  • vs中寄存器调试窗口可看出程序是多少位运行的及cpu寄存器使用情况

    如果不清楚程序是多少位运行的 xff0c 可在vs中的调试 gt 寄存器调试窗口查看寄存器的寻址位数 xff0c 如果是32位的exe则寄存器寻址显示32位 xff0c 64位的exe则显示64位寻址 1 根据IntPtr Size来判断
  • CentOS6 Squid代理服务器的安装与配置

    一 简介 代理服务器英文全称是Proxy Server xff0c 其功能就是代理网络用户去取得网络信息 Squid是一个缓存Internet 数据的软件 xff0c 其接收用户的下载申请 xff0c 并自动处理所下载的数据 当一个用户想要
  • c++中类型用new和不用new的区别

    解析一 xff1a new创建类对象 xff0c 使用完后需使用delete删除 xff0c 跟申请内存类似 所以 xff0c new有时候又不太适合 xff0c 比如在频繁调用场合 xff0c 使用局部new类对象就不是个好选择 xff0
  • C# Thread开启线程几种方式

    using System using System Collections Generic using System Linq using System Text using System Threading using System Th
  • C#多线程与UI响应 防止界面假死不响应(子线程创建的窗体获取消息响应用Application.DoEvent )

    一 xff0e 概述 在使用C 进行应用程序设计时 xff0c 经常会采用多线程的方式进行一些后台任务的工作 对于不同的应用场景 xff0c 使用的策略也不尽相同 1 后台循环任务 xff0c 少量UI更新 xff1a 例如批量上传文件 x
  • c#中通过截获windows消息禁止改变窗体大小

    private const int WM SYSCOMMAND 61 0x112 private const int MF REMOVE 61 0x1000 private const int SC RESTORE 61 0xF120 还原