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 !
Inside your overridden
WndProc()1 method, you can send a result value back to the caller by setting theTMessage.Resultfield. Or calling theinheritedmethod for default handling.1: BTW, the virtual
WndProc()method also exists in FreePascal/Lazarus. There is also a virtualMainWndProc()method, too. So, you don't need to useSetWindowLongPtr()on yourTFormat all, in either compiler.