Board index » delphi » TApplication.OnMessage not responding to some messages?

TApplication.OnMessage not responding to some messages?

I'm using Delphi 1.0 and have a simple OnMessage handler that isn't being
called when I do a SendMessage, but IS being called when a PostMessage is
used...  What am I doing wrong?

 

Re:TApplication.OnMessage not responding to some messages?


Quote
jlem...@myriad.net wrote:

> I'm using Delphi 1.0 and have a simple OnMessage handler that isn't being
> called when I do a SendMessage, but IS being called when a PostMessage is
> used...  What am I doing wrong?

OnMessage only receives events that went into the message queue.
Not all events go into the message queue.
You have to override the message handler:

program Sweeper;

uses
  Forms, Messages, WinTypes, WinProcs,
  Unit1 in 'UNIT1.PAS' {Form1};

{$R *.RES}
var
  OldWndProc: TFarProc;

function NewWndProc(hWndAppl: HWnd; Msg,wParam: Word; lParam: Longint): Longint; export;
begin
  Result:=0;
  case Msg of
    WM_SPOOLERSTATUS: {bla bla};
    WM_QUERYOPEN: {bla bla};
    WM_QUERYENDSESSION: {bla bla};
    else Result:=CallWindowProc(OldWndProc,hWndAppl,Msg,wParam,lParam);
  end;
end;

begin
  Application.CreateForm(TForm1, Form1);
  OldWndProc:=
    TFarProc(SetWindowLong(Application.Handle,GWL_WNDPROC,longint(@NewWndProc)));
  Application.Run;
end.

-Paul

Other Threads