我有一个程序,希望在窗口最大化时限定窗口的位置和大小。比如窗口最大化后的Top = 100;在OnCanResize和OnResize中加入类似的代码,窗口只会先最大化到满屏再让Top = 100,这样闪动的非常利害。有没有办法让窗口最大化时直接到达Top = 100的位置,就好象屏幕的上边缘就在Top = 100处一样?

解决方案 »

  1.   

    参考如下:  private
      procedure WMGetMinMaxInfo( var Message:TWMGetMinMaxInfo ); message WM_GETMINMAXINFO;
    procedure TForm1.WMGetMinMaxInfo( var Message :TWMGetMinMaxInfo ); 
    begin 
    with Message.MinMaxInfo^ do 
    begin
    ptMaxSize.X := 1000; {最大化时宽度}
    ptMaxSize.Y := 1000; {最大化时高度}
    ptMaxPosition.X :=10; {最大化时左上角横坐标}
    ptMaxPosition.Y :=10; {最大化时左上角纵坐标}
    end; 
    Message.Result := 0; {告诉Windows你改变了 minmaxinfo} 
    inherited; 
    end;
      

  2.   

    private
        procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
       
        procedure TForm1.WMSysCommand(var Message: TWMSysCommand);
        begin
          case Message.CmdType of
            61488 :
            begin
              left := 0;
              Top := 100;
              width := screen.Width;
              height := screen.Height - 100;
            end;
            else inherited;
          end;
        end;
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure WMGETMINMAXINFO(var MSG:TWMGETMINMAXINFO); message WM_GETMINMAXINFO;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    TYPE
     {struct pointed to by WM_GETMINMAXINFO IParam}//内部信息结构
     PMinMaxInfo=^MinMaxInfo;
     {$externalsym tagminmaxinfo }
     tagminmaxinfo=packed record
     ptreserved:Tpoint;
     ptmaxsize:Tpoint;
     ptmaxposition:Tpoint;
     ptmintracksize:Tpoint;
     ptmaxtracksize:Tpoint;
    end;
    var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.WMGETMINMAXINFO(var MSG:TWMGETMINMAXINFO);
    begin
    inherited;
    with msg.MinMaxInfo^ do
    begin
    ptmintracksize.X:=form1.Width;
    ptmaxtracksize.X:=form1.Width;
    ptmintracksize.Y:=form1.Height;
    ptmaxtracksize.Y:=form1.Height;
    end;
    end;
    procedure TForm1.FormCreate(Sender: TObject);
    beginend;end.
      

  4.   

    谢谢大家的帮助,insert2003(高级打字员) 的方法最简单明白,(xiaoxiao197821(你的笑对我很重要) 的方法是我最开始用的方法,但是效果不好,自己可以试一下。只有50分,怎么分呢?:)