Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use the following code in a series of programs; one program launches programs, and when each program finishes, they send a message back to the launcher that they have finished. The key to the program is using the HWND_BROADCAST parameter: the message is sent to all running programs on the computer, but of course it is handled only by those who have the correct message handler. In the program which has to send the message, write</p> <blockquote> <p>SendMessage (HWND_BROADCAST, RegisterWindowMessage ('message'), 0, 0);</p> </blockquote> <p>Obviously, you would replace 'message' with some string which is a constant in both programs (the one that sends and the one that receives).</p> <p>I don't recommend the use of the lparam parameter of SendMessage in order to pass data to the receiving program; this is supposed to be a pointer, and of course a pointer to data in program 1 would point to garbage in program 2. One could cast a longint to a pointer and send that, which would then have to be dereferenced on the receiving side</p> <p>In the receiving program,</p> <pre><code>type TWMMYMessage = record Msg: Cardinal; // ( first is the message ID ) Handle: HWND; // ( this is the wParam, Handle of sender) Info: Longint; // ( this is lParam, pointer to our data) Result: Longint; end; procedure TForm1.FormCreate(Sender: TObject); begin wm_Launcher:= RegisterWindowMessage ('message') // wm_launcher is a private member of TForm . . . end; procedure TForm1.DefaultHandler(var Message); var ee: TWMMYMessage; begin with TMessage (Message) do begin if (Msg = wm_Launcher) then begin ee.Msg:= Msg; ee.Handle:= wParam; ee.Info:= lParam; // Checking if this message is not from us if ee.Handle &lt;&gt; Handle then WmMyMessage(ee); end else inherited DefaultHandler(Message); end; end; procedure TForm1.WmMyMessage(var Msg: TWMMYMessage); begin startbtnclick (nil) // here we actually do something when the message is received end; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload