How to intercept a click on the forms' minimize button (Views: 27)
Problem/Question/Abstract: Does anybody know how to capture the minimize button press and act on it before it actually minimizes the form? Answer: You should intercept WM_SYSCOMMAND messages like this: unit Unit1; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) public procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.WMSysCommand; begin if (Msg.CmdType = SC_MINIMIZE) or (Msg.CmdType = SC_MAXIMIZE) then MessageBeep(0); DefaultHandler(Msg); end; end. |