B
B Rubble
I am trying to port some 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
}
================================================================
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
}
================================================================