[Delphi] bsNone 인 폼에서 드래그 및 크기조절
- 07-11
- 3,026 회
- 0 건
[code]
unit Area;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Mask, Vcl.ExtCtrls,
JvExControls, JvButton, JvNavigationPane, Vcl.Buttons;
type
TFrmArea = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
Memo1: TMemo;
JvNavIconButton1: TJvNavIconButton;
Button1: TButton;
BitBtn1: TBitBtn;
SpeedButton1: TSpeedButton;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure WMNCHitTest(var message: TWMNCHitTest); message WM_NCHITTEST;
private
public
{ Public declarations }
end;
const
Edge = 5;
var
FrmArea: TFrmArea;
implementation
{$R *.dfm}
{ TFrmArea }
procedure TFrmArea.CreateParams(var Params: TCreateParams);
begin
BorderStyle := bsNone;
inherited;
Params.WndParent := 0;
Params.ExStyle := Params.ExStyle or WS_EX_APPWINDOW;
end;
procedure TFrmArea.FormCreate(Sender: TObject);
begin
FormResize(Sender);
end;
procedure TFrmArea.FormResize(Sender: TObject);
var
WindowRgn, HoleRgn : HRgn;
begin
WindowRgn := 0;
GetWindowRgn(Handle, WindowRgn);
DeleteObject(WindowRgn);
WindowRgn := CreateRectRgn(0, 0, Width, Height);
HoleRgn := CreateRectRgn(Edge, Edge+Panel1.Height+Edge, Width-Edge, Height-Edge);
CombineRgn(WindowRgn, WindowRgn, HoleRgn, RGN_DIFF);
SetWindowRgn(Handle, WindowRgn, TRUE);
DeleteObject(HoleRgn);
end;
procedure TFrmArea.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(Handle, WM_NCLBUTTONDOWN, htCaption, 0);
end;
procedure TFrmArea.WMNCHitTest(var Message: TWMNCHitTest);
var
P: TPoint;
begin
inherited;
P := ScreenToClient(Message.Pos);
with Message do
begin
if Result = htClient then Exit;
Result := htCaption;
if P.Y < Edge then
begin
if P.X < Edge then
Result := htTopLeft
else if P.X > ClientWidth - Edge then
Result := htTopRight
else
Result := htTop;
end
else if P.Y > ClientHeight - Edge then
begin
if P.X < Edge then
Result := htBottomLeft
else if P.X > ClientWidth - Edge then
Result := htBottomRight
else
Result := htBottom;
end
else
begin
if P.X < Edge then
Result := htLeft
else if P.X > ClientWidth - Edge then
Result := htRight
end;
end;
end;
end.
[/code]