Solved

Windows programming

Posted on 2002-06-04
6
198 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now