⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitmain.pas

📁 演示如何设置窗口的最大,最小值
💻 PAS
字号:
unit UnitMain;

interface

{
   This example show how you can specify the minimum and maximum sizes
   of a window, showing it directly to the user by blocking him during
   resize.
   It also shows predefined size and position of windows when Maximizing it.
}
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

type

  TfrmRestrictSize = class(TForm)
    Memo1: TMemo;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label2: TLabel;
    Label4: TLabel;
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowSize;
    // You must handle the WM_GETMINMAXINFO message
    procedure RestrictSize(var msg: TMessage); message WM_GETMINMAXINFO;
  end;

var
  frmRestrictSize: TfrmRestrictSize;

implementation

{$R *.DFM}

procedure TfrmRestrictSize.ShowSize;
begin
   Label3.Caption := IntToStr(Width);
   Label4.Caption := IntToStr(Height);
end;
{
procedure TfrmRestrictSize.RestrictSize(var Msg: TMessage);
var
   p: ^TPoint;
begin
   p := Pointer(Msg.lParam+1* SizeOf(TPoint));
   p^.x := 450;
   p^.y := 450;
   p := Pointer(Msg.lParam+2* SizeOf(TPoint));
   p^.x := 200;
   p^.y := 200;
   p := Pointer(Msg.lParam+3* SizeOf(TPoint));
   p^.x := 320;
   p^.y := 200;
   p := Pointer(Msg.lParam+4* SizeOf(TPoint));
   p^.x := 640;
   p^.y := 480;
end;
}

procedure TfrmRestrictSize.RestrictSize(var Msg: TMessage);
var
   p: PMinMaxInfo;
begin
// The lParam contains a pointer on a structure of type TMinMaxInfo
   p := PMinMaxInfo(Msg.lParam);
// This represents the size of the Window when Maximized
   p.ptMaxSize.x := 320;
   p.ptMaxSize.y := 240;
// This represents the position of the Window when Maximized
   p.ptMaxPosition.x := 10;
   p.ptMaxPosition.y := 10;
// This represents the minimum size of the Window
   p.ptMinTrackSize.x := 320;
   p.ptMinTrackSize.y := 240;
// This represents the maximum size of the Window
   p.ptMaxTrackSize.x := 400;
   p.ptMaxTrackSize.y := 320;
end;

procedure TfrmRestrictSize.FormShow(Sender: TObject);
begin
   ShowSize;
end;

procedure TfrmRestrictSize.FormResize(Sender: TObject);
begin
   ShowSize;
end;




end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -