Tommi Prami 130 Posted August 18, 2021 I am bit lost on how I can handle user message and return value to the caller app, which is using SendMessage API. I've got following code UM_STATUS = WM_USER + 333; ... // On form procedure WmPrintPreviewStatus(var Msg: TMessage); message UM_PRINT_PREVIEW_STATUS; // and implementation procedure TMyForm.WmStatus(var Msg: TMessage); var LResult: NativeInt; begin LResult := 1; if Assigned(FStatusObject) then if FStatusObject.Status = statFinished then LResult := 2; Msg.Result := LResult; end; What I am now more than less confused that message structure in MSDN looks pretty different (below) and Will my code work, so that caller can use something like MyResult = SendMessage(HWND, UM_STATUS...) typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; DWORD lPrivate; } MSG, *PMSG, *NPMSG, *LPMSG; Share this post Link to post
David Heffernan 2345 Posted August 18, 2021 The sender of the message will receive the return value that you set. Perhaps a bigger problem is that vcl window recreation means that your form's window handle is liable to change during its lifetime. For ipc using windows messages you need to use stable window handles. Share this post Link to post
Tommi Prami 130 Posted August 18, 2021 3 hours ago, David Heffernan said: The sender of the message will receive the return value that you set. Perhaps a bigger problem is that vcl window recreation means that your form's window handle is liable to change during its lifetime. For ipc using windows messages you need to use stable window handles. We acquire HWND of window first then we try to poll window couple of seconds, when status is set, we close from . This is GUI testing AutoIT script which should poll that particular form. Share this post Link to post
Remy Lebeau 1392 Posted August 18, 2021 11 hours ago, Tommi Prami said: What I am now more than less confused that message structure in MSDN looks pretty different (below) and Will my code work, so that caller can use something like MyResult = SendMessage(HWND, UM_STATUS...) Yes, that will work fine. The VCL's internal WndProc that will first receive the message (StdWndProc() in System.Classes.pas) copies the tagMSG values to a local TMessage, then dispatches that TMessage to handlers, and then returns the TMessage.Result value back to the original sender. 1 Share this post Link to post
Tommi Prami 130 Posted August 19, 2021 13 hours ago, Remy Lebeau said: Yes, that will work fine. The VCL's internal WndProc that will first receive the message (StdWndProc() in System.Classes.pas) copies the tagMSG values to a local TMessage, then dispatches that TMessage to handlers, and then returns the TMessage.Result value back to the original sender. Thanks man! Some Windows messages in Delphi guru should write detailed blog post. There was examples but could not find any that would explain all the plumbing and returning values. 😄 Share this post Link to post