bsNone 인 폼에서 드래그 및 크기조절

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.

Comments

Tips & Tech

Windows node.js 와 npm 업데이트(업그레이드)
Windows 윈도우11 시작 메뉴 위치 변경(가운데, 왼쪽)
Delphi 중복 실행 방지
Linux yum 에서 Thread died in Berkeley DB library 오류
Linux VNSTAT 설치하기
Linux 로그 삭제 및 비우기(?)
Others [FTP] 500 Illegal PORT command.
Linux .htaccess 를 이용해서 https 이동하기
Dev tips Imagek 를 이용한 썸네일 생성
GnuBoard 1364 : Field 'xxxxx' doesn't have a default value
Linux 윈도우 프로그램 실행 (centos7, wine 7.0)
Windows IPv6 켜기, 끄기
GnuBoard 회원 가입일 기준으로 이용기간 정하기
GnuBoard sql_fetch, sql_query 안쓰고 직접 mysql 사용하기
Dev tips PHP 수정시 적용이 안되는 경우 해결 (opcache 중지)
Others [맥OS] 마우스 휠 스크롤 방향 윈도우와 일치시키는 방…
Dev tips [Ruby] 윈도우에서 pod install 실행시 UTF-8 오류
Dev tips [Ruby] Could not open library 'libcurl'
Dev tips [Android] Error type 3: Activity class {com.?.MainAc…
Dev tips Curl 을 이용하여 파일 다운로드
Dev tips Curl 을 이용하여 json 을 post 보내기
Windows 설치하려고 하는 앱이 Microsoft에서 확인된 앱이 아닙…
Delphi Glyph 에 사용할 이미지 생성하기
Python 파이썬 아나콘다 업데이트
Views Delphi bsNone 인 폼에서 드래그 및 크기조절
Linux Composer 설치하기
Windows WinHTTP 사용에서 12175 에러 발생시
Dev tips 날짜필드 연장하기
Linux Swap 생성/수정
Linux 바이러스 검사