Early trap then Close Window procedure

Spread the love

Early trap then Close Window procedure

Procedure TForm1.HandleMessage(var Msg:TMessage);
begin
 if msg.msg = WM_CLOSE //You can insert there other message constans from windows unit.
 then
  begin
   {Your code when user clicked close button}
   showmessage('You can not close this window!');
  end
 else form1.wndproc(msg); //if not closed system handle the message default
end;
procedure TForm1.Create(Sender:Tobject);
begin
 form1.Windowproc:=form1.handlemessage; //run handling
end;