• C# 窗口函数的修改[关闭,最大化,最小化付换]


    C# 代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace 窗口函数的修改
    {
        
    public partial class Form1 : Form
        {
            
    protected override void WndProc(ref Message m)
            {
                
    //以下方法就把关闭对话框的消息改成了,最大化或最小化效果.
                switch (m.Msg)
                {
                    
    case 16://截获窗口关闭消息
                        {
                            m.Msg 
    = 274;//给窗口赋予最大化和最小化消息值
                            m.WParam = (IntPtr)61472;//61488表示最大化//61472表示最小化
                            break;                        
                        }
                    
                    
    default:
                        
    break;
                }
                
                
    base.WndProc(ref m);
            }
            
            
            
    public Form1()
            {
                InitializeComponent();
            }
        }

        

    }

    Delphi 相同功能代码:

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;

    type
      TForm1 
    = class(TForm)
      
    private
      
    protected
        
    procedure WndProc(var Message: TMessage); override;//按CTRL+空格键可以看到能被重写的父类方法,选择WndProc
        
    { Private declarations }
      
    public

      
    end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}
    //手工写实现部分
    procedure TForm1.WndProc(var Message: TMessage);
    begin
      
    if message.Msg=WM_CLOSE then
      
    begin
         Message.WParam:
    =SC_MINIMIZE;//消息的辅助参数改成最小化值
         Message.Msg:
    =WM_SYSCOMMAND;//消息类型改成工具栏按键类型(关闭,最大化和最小化按钮的类型)
      
    end;
      
    inherited//调用父类同名方法
    end;


    end.
  • 相关阅读:
    springboot启动时不加载数据库
    ElasticSearch常用的查询操作
    Windows10 搭建ElasticSearch集群服务
    windows10安装ElasticSearch7.5遇到两个警告解决方法
    MybatisPlus自动生成代码配置
    初识RabbitMQ ------基本概念
    深拷贝与浅拷贝的区别
    Java8中 LocalDateTime与Date互相转换
    Spring中常用的工具类StringUtils、DateUtils、CollectionUtils等
    SpringBoot定时任务 @Scheduled cron 表达式说明
  • 原文地址:https://www.cnblogs.com/webcyz/p/1991760.html
Copyright © 2020-2023  润新知