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();
}
}
}
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.
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.