zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    WPF and Silverlight 学习笔记:键盘输入、鼠标输入、焦点处理
    [转]Visual Studio .NET "目标平台" 说明
    WPF 使用HwndHost嵌入Win32后,无法接受Mouse_Move\Mouse_Leave消息
    c#有多少种可能导致写文件失败?
    优化性能:文本【msdn】
    解决popup不随着window一起移动的问题
    异常处理的资料
    利用bat编译WPF项目
    属性值继承
    WPF消息机制
  • 原文地址:https://www.cnblogs.com/webcyz/p/1991760.html
Copyright © 2011-2022 走看看