unit Unit2;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SysCommand;
    {
    procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHitTest;
    }
    procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLButtonDown;
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

uses unit1;

procedure TForm2.FormCreate(Sender: TObject);
var
  style : longint;
begin
  Style := GetWindowLong(Handle, gwl_style);
  Style := Style or ws_minimizebox;
  SetWindowLong(Handle, gwl_style, Style);
end;

procedure TForm2.WMSysCommand(var Message : TWMSysCommand);
begin
  case Message.CmdType of
    sc_minimize : Application.Minimize;
  else
    inherited;
  end;
end;

procedure TForm2.WMNCLButtonDown(var Message: TWMNCLButtonDown);
begin
  inherited;
  case Message.HitTest of
    HTMINBUTTON : begin
                    MessageBeep(0);
                    Message.Result := 0;
                    SendMessage(Handle, wm_syscommand, sc_minimize, LongInt(Pointer(Message.XCursor)));
                   end;
  end;
end;

{
procedure TForm2.WMNCHitTest(var Message : TWMNCHitTest);
begin
  inherited;
  case Message.Result of
    HTBOTTOM,
    HTBOTTOMLEFT,
    HTBOTTOMRIGHT,
    HTTOP,
    HTTOPLEFT,
    HTTOPRIGHT,
    HTRIGHT,
    HTLEFT : Message.Result := HTNOWHERE;
    HTMINBUTTON : MessageBeep(0);
  end;
  Label1.Caption := IntToStr(Message.XPos);
  Label2.Caption := IntToStr(Message.YPos);
end;
}

end.
