Solved

Windows programming

Posted on 2002-06-04
6
201 Views
Last Modified: 2010-04-04
hi! i have 2 programs.  program A and program B.  i want program A to communicate with program B through windows messaging wherein program B will then do something on program A's command.  thanks in advance to everyone! :)
0
Comment
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 100 total points
ID: 7053446
:)

if these programs will run on the same machine then you can use SendMessage
otherwise take a look into mailslots, pipes and sockets

for SendMessage you can simply do:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure SomeHandler(var Msg: TMessage); message WM_APP + 123;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SomeHandler(var Msg: TMessage);
begin
     case Msg.WParam of
       0: Msg.Result:=0; // ofcourse you replace this by your handler
       1: Msg.Result:=1;
     end;

     Caption:=Format('%d -> %d', [Msg.WParam, Msg.Result]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var hWin: HWND;
begin
     hWin:=FindWindow('TForm2', 'Form2');
     if hWin > 0 then
        SendMessage(hWin, WM_APP + 123, 1, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var hWin: HWND;
begin
     // finc the receiver window - the other app
     hWin:=FindWindow('TForm2', 'Form2');
     if hWin > 0 then
        SendMessage(hWin, WM_APP + 123, 0, 1);
end;

end.


you can do the same for the other app .. just change the handler

that's the basics of messaging
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7053743
don't forget Windows Atoms, too.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054552
then we could also go into Memory Mapped files and SendMessage with WM_COPYDATA :)
lots of ways to communicate in windows .. gotta love 'em :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:aikimark
ID: 7055025
You can probably accomplish this through some CORBA or COM handshaking as well.  

Directory monitoring API. (indirect Sendmessage)
DDE (an oldie)
inter-process Winsock

Dang, this list could get long.

I don't want to confuse dabestprogrammerindauniverse, so let me recommend that Lee_Nover get the points for the correct answer.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7055054
hey tnx ! :)
0
 
LVL 1

Expert Comment

by:bnemmers
ID: 7055454
I have a component at Torry's that does what you need
look for IPC. It's freeware but beware that this will not work in a NT service app.

http://www.torry.net/vcl/system/appscommunications/bmipc.zip

Good Luck Bill :-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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