Linux equivalent of Windows' SendMessage

Giatto
Date: 03/30/05


Date: Thu, 31 Mar 2005 00:17:04 +1000

I am new to Linux and trying to move my apps from Windows to Linux.
In Windows I can define a custom message and register it with the OS and by
using SendMessage(HWND_BROADCAST,...) I can send messages to multiple
applications.

How to do the same thing in Linux ? ie How to define a custom message,
register it and broadcast that message to multiple applications?

================================================================
// Following code is copied from a demo program written in Borland C++
Builder Ver 6
const AnsiString PrivateMessageID =
"{7395314D-3A02-4887-A60F-BD029D1FF009}";
int N =0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  PrivateMessage = RegisterWindowMessage(PrivateMessageID.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::WndProc(Messages::TMessage& Message)
{
  if (Message.Msg == PrivateMessage) {
     if (Message.WParam ==0){ // Display only the first message
        AnsiString S;
        S.sprintf("%d - WParam: %.05d LParam: %.05d at %s",
                  N, Message.WParam,
                  Message.LParam, AnsiString(Now()).c_str()
        );
        Memo1->Lines->Add(S);
     }
     N++;
  }
  TForm::WndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TDateTime T0, T1;
  T0 = Now();
  for (int i=0; i<100; i++)
    SendMessage(HWND_BROADCAST,PrivateMessage,i,i*10);
  T1 = Now();
  AnsiString S;
  DateTimeToString(S, "ss:zzz",T1-T0);
  Caption = S; // <--- It display around 02.804 sec on 2GHz notebook PC
}
================================================================

See also : "Sending and receiving custom messages" by Hens Zimmerman URL:
http://cc.borland.com/ccWeb.exe/listing?id=15251