RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomApplicationEvents.OnMessage Event

Occurs when the application receives a Windows message.

Pascal
property OnMessage: TMessageEvent;
C++
__property TMessageEvent OnMessage;

Use OnMessage to trap any or all Windows messages posted to all windows in the application. OnMessage occurs when an application receives a Windows message. OnMessage only receives messages that are posted to the message queue, not those sent directly with the Windows API SendMessage function. 

An OnMessage event handler allows an application to respond to messages other than those declared in the events for TApplication. If the application doesn't have a specific handler for an incoming message, the message is dispatched to the window for which it was intended, and Windows handles the message.

Warning: Caution:Thousands of messages per second flow though this event. Be careful when coding the handler, because it can affect the performance of the entire application.
Tip: Call the CancelDispatch method from an OnMessage event handler to prevent the application from forwarding the event to any other application events objects.
 

C++ Examples: 

 

/*
This example requires a TApplicationEvents and a TListBox
in the form.  Select the TApplicationEvents, double click
on the OnMessage event and add the following code to the
handler.  OnMessage is triggered when the application
receives a Windows message.
*/
void __fastcall TAppEventForm::ApplicationEventsMessage(tagMSG &Msg,
      bool &Handled)
{
    lbOnMessage->Items->Add("X:=" + IntToStr(int(Msg.pt.x)) + "|Y:=" + IntToStr(int(Msg.pt.y)));
}

 

Delphi Examples: 

{
This example requires a TApplicationEvents and a TListBox
in the form.  Select the TApplicationEvents, double click
on the OnMessage event and add the following code to the
handler.  OnMessage is triggered when the application
receives a Windows message.
}
procedure TMainForm.ApplicationEventsMessage(var Msg: tagMSG;
  var Handled: Boolean);
begin
  lbOnMessage.Items.Add('X:=' + IntToStr(Msg.pt.x) + '|Y:=' + IntToStr(Msg.pt.y));
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!