2005. június 30., csütörtök

Minimze and close the application by simple rolling your mouse over the applications system buttons


Problem/Question/Abstract:

How can I minimize Close the application by rolling my mouse over the system controls

Answer:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    procedure lik(var Msg: TWMNCHITTEST); message WM_NCHITTEST;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  tx: Boolean;
implementation

{$R *.DFM}

procedure TForm1.lik(var Msg: TWMNCHITTEST);
begin
  inherited; //respond to other commands
  if tx = true then //check if it's enabled
  begin
    if Msg.Result = Windows.HTMINBUTTON then
      Application.Minimize
    else if Msg.Result = Windows.HTCLOSE then
      Close; //make widows to do it
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  tx := True; //This enables the function
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  tx := False; //This disables it
end;

end.

Nincsenek megjegyzések:

Megjegyzés küldése