Главная » Delphi » Основная » Как изменять размеры окна без рамки.

Как изменять размеры окна без рамки.

16:00
unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure WMNCHitTest(var msg: TWMNCHitTest); message wm_NCHitTest;
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
{ TForm1 }
 
procedure TForm1.WMNCHitTest(var msg: TWMNCHitTest);
const
  Tolerance = 5;
var
  P: TPoint;
  OverRight: Boolean;
  OverLeft: Boolean;
  OverTop: Boolean;
  OverBottom: Boolean;
begin
  with Msg do
  begin
    P := ScreenToClient(Point(XPos, YPos));
    OverRight := Abs(P.x - Width) < Tolerance;
    OverLeft := Abs(P.x) < Tolerance;
    OverTop := Abs(P.y) < Tolerance;
    OverBottom := Abs(P.y - Height) < Tolerance;
    if (Abs(P.x) < 20) and (Abs(P.y) < 20) then
      Result := HTTOPLEFT
    else if (Abs(P.x - Width) < 20) and (Abs(P.y) < 20) then
      Result := HTTOPRIGHT
    else if (Abs(P.x - Width) < 30) and (Abs(P.y - Height) < 30) then
      Result := HTBOTTOMRIGHT
    else if (Abs(P.x) < 30) and (Abs(P.y - Height) < 30) then
      Result := HTBOTTOMLEFT
    else if OverRight then
    begin
      if OverTop then
        Result := HTTOPRIGHT
      else if OverBottom then
        Result := HTBOTTOMRIGHT
      else
        Result := HTRIGHT;
    end
    else if OverLeft then
    begin
      if OverTop then
        Result := HTTOPLEFT
      else if OverBottom then
        Result := HTBOTTOMLEFT
      else
        Result := HTLEFT;
    end
    else if OverTop then
      Result := HTTOP
    else if OverBottom then
      Result := HTBOTTOM
    else
      Result := HTCLIENT;
  end;
 
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
   borderstyle:=bsNone;
end;
 
end.