Broadcast message lazarus / 21-General ---------------------------------------------------------------------- pcurtis · 2021-01-31 20:31 Hi All, how can I send a message to all running applications? I've tried this and it doesn't work Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Windows, StdCtrls;  const  WM_MYMSG = WM_USER + 101; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public    procedure WMMymsg(var Msg: TMessage); message WM_MYMSG;  end; var  Form1: TForm1; implementation {$R *.lfm} procedure TForm1.Button1Click(Sender: TObject);begin  PostMessage(HWND_BROADCAST, WM_MYMSG, 1, 0);end; procedure TForm1.WMMymsg(var Msg: TMessage);begin  ShowMessage('here');end; end. ---------------------------------------------------------------------- jamie · 2021-01-31 21:11 PostMessage(HWND_BROADCAST,AMessageValue, option1, option2); The HWND_BROADCAST handle is a system wide window  , it will send the message to all top level windows ---------------------------------------------------------------------- pcurtis · 2021-01-31 21:27 Did you look at the posted code. See line 36. It doesn't work. If I change HWND_BROADCAST to self.handle it works, but I need to broadcast. ---------------------------------------------------------------------- jamie · 2021-01-31 22:26 that message only goes to the top level window which in this case is the Application.Handle I see that Laz does not provide a OnMessage event to make this easier. You need to hook the Application.Handle window.. You can't use the MsgHook unit for that you need to do it the hard way.. ---------------------------------------------------------------------- 440bx · 2021-01-31 23:15 Quote from: pcurtis on January 31, 2021, 10:27:16 pmIt doesn't work. If I change HWND_BROADCAST to self.handle it works, but I need to broadcast. You need to read the documentation for the APIs PostMessage, SendMessage and RegisterWindowMessage.   There are restrictions placed on broadcasting WM_USER messages.  In a few words, don't expect system wide broadcasting of a WM_USER message to work.  Allowing that to work would enable applications to maliciously cause problems in other applications that use user defined messages to carry out some of their functions. ---------------------------------------------------------------------- jamie · 2021-01-31 23:48 you take the fun out of it  anyways I think you can send user messages because it only goes to the top level window which In most cases is not a user form but just a message handler capture window.  But in this case its hard to get to because its in the application class and that window basically only handles known messages and ignores all others. Only apps that are special in this case for example would be interacting there.  But who knows.. I guess you could just send a WM_POWERBROADCAST message yourself !  There is also the BroadCastSystemMessage API call too ---------------------------------------------------------------------- pcurtis · 2021-02-01 02:50 ok then. How can I enumerate all top level forms and get their handles? ---------------------------------------------------------------------- jamie · 2021-02-01 21:54 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser- enumwindows