- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Subclass the window procedure for a TForm

Question:

How can I subclass the window procedure for a TForm?

Answer:

Override the WinProc procedure for the form. The following example

overrides the window procedure for the form, and responds to the

WM_CANCELMODE message, indicating that a messagebox or other dialog

box has been executed.



Example:



type

  TForm1 = class(TForm)

    Button1: TButton;

    procedure WndProc (var Message: TMessage); override;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;



var

  Form1: TForm1;



implementation



{$R *.DFM}



procedure TForm1.WndProc (var Message: TMessage);

begin

  if Message.Msg = WM_CANCELMODE then begin

    Form1.Caption := 'A dialog or message box has popped up';

  end else

  inherited

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

  ShowMessage('Test Message');

end;




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile