bramme
asked on
Send a message to a application
I have 2 applications, and i want to send a message from one application to the other one.
How do I do that?
How do I do that?
listening
sendmessage
brb with example, want to beat other people to it!!!
brb with example, want to beat other people to it!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What do you mean by message? If you mean windows message, then Craig's done that. If you mean message like "hello world" then a good place to look is the chat example in Delphi5\Demos\Internet\Cha t
I think what you have in mind here is pipes - you need the Windows API functions *namedpipes -
CreateNamedPipe,
ConnectNamedPipe,
TransactNamedPipe
and the others.
If this isn't enough, I can write a small demo for you.
CreateNamedPipe,
ConnectNamedPipe,
TransactNamedPipe
and the others.
If this isn't enough, I can write a small demo for you.
yes sburck name the pipes :)
bear in mind that you can't create named pipe servers on '95 or '98...
listening,
ASKER
allright craig capel
so far so right, but how do I send a string to another application that i have written, and that application has then a event?
so far so right, but how do I send a string to another application that i have written, and that application has then a event?
Hi,
compile these two apps and run to see a demo of sending and recieving messages :
unit SendMsgTimeoutSendU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{Whoops! This function is imported in the Delphi source code incorrectly; the
return value should be BOOL, not LRESULT}
function SendMessageTimeout(hWnd: HWND; Msg: UINT; wParam: WPARAM;
lParam: LPARAM; fuFlags, uTimeout: UINT; var lpdwResult: DWORD):BOOL; stdcall;
var
Form1: TForm1;
UserMessage: UINT; // holds our user defined message identifier
implementation
{$R *.DFM}
{re-link the external function}
function SendMessageTimeout; external user32 name 'SendMessageTimeoutA';
procedure TForm1.FormCreate(Sender: TObject);
begin
{register the user defined Windows messsage}
UserMessage := RegisterWindowMessage('Sen dMessageTi mout Test Message');
end;
procedure TForm1.Button1Click(Sender : TObject);
var
MsgResult: DWORD;
begin
{send the message, and time out after 300 milliseconds}
SendMessageTimeout(HWND_TO PMOST, UserMessage, 0, 0,
SMTO_NORMAL, 300, MsgResult);
{indicate that the SendMessageTimeout function has returned}
ShowMessage('Returned');
end;
end.
unit SendMstTimeoutGetU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
ProgressBar1: TProgressBar;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DefaultHandler(var Msg); override;
public
{ Public declarations }
end;
var
Form1: TForm1;
UserMessage: UINT; // holds our user defined message identifier
implementation
{$R *.DFM}
procedure TForm1.DefaultHandler(var Msg);
var
iLoop: Integer; // general loop counter
begin
{process message normally}
inherited DefaultHandler(Msg);
{if this is our user defined message...}
if TMessage(Msg).Msg=UserMess age then
begin
{...display some user interface objects}
ProgressBar1.Visible := TRUE;
Label2.Visible := TRUE;
Form1.Repaint;
{animate the progress bar for a short time}
for iLoop := 0 to 100 do
begin
ProgressBar1.Position := iLoop;
Sleep(10);
end;
{turn off the user interface objects}
ProgressBar1.Visible := FALSE;
Label2.Visible := FALSE;
{indicate that the message was handled}
TMessage(Msg).Result := 1;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{register the user defined Windows message}
UserMessage := RegisterWindowMessage('Sen dMessageTi mout Test Message');
end;
end.
compile these two apps and run to see a demo of sending and recieving messages :
unit SendMsgTimeoutSendU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{Whoops! This function is imported in the Delphi source code incorrectly; the
return value should be BOOL, not LRESULT}
function SendMessageTimeout(hWnd: HWND; Msg: UINT; wParam: WPARAM;
lParam: LPARAM; fuFlags, uTimeout: UINT; var lpdwResult: DWORD):BOOL; stdcall;
var
Form1: TForm1;
UserMessage: UINT; // holds our user defined message identifier
implementation
{$R *.DFM}
{re-link the external function}
function SendMessageTimeout; external user32 name 'SendMessageTimeoutA';
procedure TForm1.FormCreate(Sender: TObject);
begin
{register the user defined Windows messsage}
UserMessage := RegisterWindowMessage('Sen
end;
procedure TForm1.Button1Click(Sender
var
MsgResult: DWORD;
begin
{send the message, and time out after 300 milliseconds}
SendMessageTimeout(HWND_TO
SMTO_NORMAL, 300, MsgResult);
{indicate that the SendMessageTimeout function has returned}
ShowMessage('Returned');
end;
end.
unit SendMstTimeoutGetU;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
ProgressBar1: TProgressBar;
Label2: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DefaultHandler(var Msg); override;
public
{ Public declarations }
end;
var
Form1: TForm1;
UserMessage: UINT; // holds our user defined message identifier
implementation
{$R *.DFM}
procedure TForm1.DefaultHandler(var Msg);
var
iLoop: Integer; // general loop counter
begin
{process message normally}
inherited DefaultHandler(Msg);
{if this is our user defined message...}
if TMessage(Msg).Msg=UserMess
begin
{...display some user interface objects}
ProgressBar1.Visible := TRUE;
Label2.Visible := TRUE;
Form1.Repaint;
{animate the progress bar for a short time}
for iLoop := 0 to 100 do
begin
ProgressBar1.Position := iLoop;
Sleep(10);
end;
{turn off the user interface objects}
ProgressBar1.Visible := FALSE;
Label2.Visible := FALSE;
{indicate that the message was handled}
TMessage(Msg).Result := 1;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
{register the user defined Windows message}
UserMessage := RegisterWindowMessage('Sen
end;
end.
mmm...
Barry, i know how you feel, it happens to me all the time :)
;-)