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



Relevant Pages

  • Re: gcc for windows?
    ... installed gcc on Windows for a while - why faff around with development ... On 64-bit Linux, people generally build ... tends to have a lower incidence of register spills in non-leaf functions ... So it avoids spilling registers onto the stack by passing more stuff on the stack? ...
    (comp.lang.c)
  • Re: Computer guru on switching to Linux from Windows: it sucks, dont do it.
    ... My advice to you would be to register here... ... download costs of Linux distributions in the outback to new Windows ... Of all software vendors in existence, Microsoft has the biggest ...
    (comp.os.linux.setup)
  • Re: China Replaces Windoze With Linux, World To Follow
    ... >>A poor Communist country tries to enhance Linux, ... >>eventually be 70% as good as Windows. ... Why has Microsoft chosen to make removing spyware ... I think you'll find that the "Do you want to register your downloads ...
    (comp.security.firewalls)
  • Slightly off topic: Help a Cheapskate
    ... If you register you can get their Standard Version Free. ... register, and download it. ... I could win a FREE Upgrade to their PRO Version which compiles apps for Windows, Linux and Apple Mac. ...
    (alt.os.linux.suse)
  • z Linux es más seguro que Windows. Confirmado
    ... Un reciente estudio de The Register vuelve a poner en el candelero la ... operativos Windows y Linux en sus ediciones servidoras. ... The Register ha comparado las 40 últimas vulnerabilidades y parches ... segura de Windows - como en Red Hat Enterprise Linux AS v.3. ...
    (microsoft.public.de.german.windowsxp.sonstiges)