Board index » delphi » Send Message to TApplication Object

Send Message to TApplication Object

I am passing messages between 16 bit and 32 bit applications. To pass
data between the applications I use WM_COPYDATA, which in the future
I will use to pass data between 32 bit applications.

I can override the message processing by assigning to
application.OnMessage, and all works fine with POSTED messages.

However, if I use SendMessage(..) I get nothing in my message override
routine.

I looked in the VCL source code at the TApplication object. In its
OnCreate method, it uses a window class that has DefWndProc as its
registered message handler, so I presume that the post message is
being processed normally by TApplication.ProcessMessage, but ANY sent
message gets kicked straight through to the windows default handler.

Any suggestions on how to get around this?

TIA
Paul Kennedy
Hexel (UK) Ltd

 

Re:Send Message to TApplication Object


Quote
he...@fastnet.co.uk (Paul Kennedy) wrote:
>I am passing messages between 16 bit and 32 bit applications. To pass
>data between the applications I use WM_COPYDATA, which in the future
>I will use to pass data between 32 bit applications.
>I can override the message processing by assigning to
>application.OnMessage, and all works fine with POSTED messages.
>However, if I use SendMessage(..) I get nothing in my message override
>routine.
>I looked in the VCL source code at the TApplication object. In its
>OnCreate method, it uses a window class that has DefWndProc as its
>registered message handler, so I presume that the post message is
>being processed normally by TApplication.ProcessMessage, but ANY sent
>message gets kicked straight through to the windows default handler.
>Any suggestions on how to get around this?

I later found that the previous paragraph was a red herring. The
TApplication OnCreate method registers its windows class with the
default windows procedure, then overrides this using SetWindowLong to
set up the windows procedure.

If you override message handling for the application by assigning to
application.OnMessage, your message handler is called by
TApplication.ProcessMessages. This is the procedure that picks
messages from your message queue and dispatches them to the windows
procedure. This contains the following

    begin
      Handled := False;
      if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
      if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
        not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end

The dispatch message passes the message through to the windows
procedure. However, if the message comes via SendMessage, windows
calls the registered window procedure direct, bypassing the call to
application.FOnMessage().

I cured this by calling application.FOnMessage in the windows message
procedure TApplication.WndProc().

Other Threads