Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Send a message to a application

Posted on 2000-05-01
13
Medium Priority
?
396 Views
Last Modified: 2008-02-20
I have 2 applications, and i want to send a message from one application to the other one.
How do I do that?
0
Comment
Question by:bramme
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +4
13 Comments
 
LVL 4

Expert Comment

by:mhervais
ID: 2765943
listening
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2765973
sendmessage
 brb with example, want to beat other people to it!!!
0
 
LVL 2

Accepted Solution

by:
craig_capel earned 135 total points
ID: 2766006
var
 h: hwnd;
begin
   winexec('c:\windows\notepad.exe',1);
//   h:=getforegroundwindow;
    h:=findwindow(nil,'untitled - notepad');
   sendmessage(h,wm_close,0,0);
     //wm_hide
     //wm_show     // just look it up easy

end;


OR.... you can use DDE, and talk to it like i'm not quite sure what you mean now....

i have examples on dde if your intrested?...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:mullet_attack
ID: 2766032
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\Chat
0
 
LVL 3

Expert Comment

by:sburck
ID: 2766050
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.

0
 
LVL 4

Expert Comment

by:mhervais
ID: 2766421
yes sburck name the pipes :)
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2768109
bear in mind that you can't create named pipe servers on '95 or '98...
0
 
LVL 3

Expert Comment

by:smurff
ID: 2768418
listening,
0
 

Author Comment

by:bramme
ID: 2769942
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?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2770662
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('SendMessageTimout Test Message');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  MsgResult: DWORD;
begin
  {send the message, and time out after 300 milliseconds}
  SendMessageTimeout(HWND_TOPMOST, 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=UserMessage 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('SendMessageTimout Test Message');
end;

end.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2770824
mmm...
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2770932
Barry, i know how you feel, it happens to me all the time :)
0
 
LVL 17

Expert Comment

by:inthe
ID: 2771097
;-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question