Reputation: 1
I am moving some code for a Windows message handler/intercepter from Lazarus to Delphi.
In Lazarus, I had this code:
function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
(Handle WM_ messages)
result:=CallWindowProc(PrevWndProc,Ahwnd, uMsg, WParam, LParam);
end;
(with this invoked in the FormCreate)
PrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Self.Handle,GWL_WNDPROC,PtrInt(@WndCallback)));
Notice that WndCallback can return LRESULT to the invoking SendMessage on the non-Pascal application.
In Delphi, Windows.WNDPROC does not exist, so I created my own WndProc() that overrides the WndProc() in the VCL. However, WndProc() is a procedure, not a function, so it cannot return a result to the invoking SendMessage. Is there a way to return a result from a Delphi WndProc() ?
Thanks !
Upvotes: 0
Views: 445
Reputation: 595991
Inside your overridden WndProc()
1 method, you can send a result value back to the caller by setting the TMessage.Result
field. Or calling the inherited
method for default handling.
procedure TMyForm.WndProc(var Message: TMessage);
begin
(Handle WM_ messages)
if (want to return a value) then
Message.Result := ...
else
inherited;
end;
1: BTW, the virtual WndProc()
method also exists in FreePascal/Lazarus. There is also a virtual MainWndProc()
method, too. So, you don't need to use SetWindowLongPtr()
on your TForm
at all, in either compiler.
Upvotes: 4