就是一个EXE如何通过消息来控制另一个EXE的

解决方案 »

  1.   

    //form1发送控制消息 到form2 注意form1 和form2不是同一个程序
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    var t:hwnd;
    begin
    t:=findwindow(nil,'form2');//form2为窗口caption
    if t<>0 then
    sendmessage(t,1099,0,0);
    end;
    end.
    //form2 接受到后处理
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm2 = class(TForm)
        function FormHelp(Command: Word; Data: Integer;
          var CallHelp: Boolean): Boolean;
      private
        { Private declarations }
      public
       procedure showmsg(var msg:tmessage);message  1099;
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.DFM}procedure tform2.showmsg(var msg:tmessage);
    begin
    showmessage('收到消息');
    end;
      

  2.   

    对不起 一时匆忙 form2中请去掉
    function FormHelp(Command: Word; Data: Integer;
          var CallHelp: Boolean): Boolean;
      

  3.   

    我倒是有一个vc写的例子,要的话留mail
      

  4.   

    使用函数:
    例如   
    var
      PStartupInfo: TStartupInfo;
      aProcessInfo: TProcessInformation;
    begin   
      CreateProcess(nil,PChar(pchar('C:\WINDOWS\NOTEPAD.EXE'),
          nil, nil, False, DETACHED_PROCESS, nil, nil, PStartupInfo, aProcessInfo);
    end;
      

  5.   

    sunny518(灵犀) (
    您好,你的方法是正确的,但是如果A程序是自己开发的,B程序不是自己开发的,这样的情况该如何处理呢?
      

  6.   

    是呀,难就难在这里了,比如要用A程序控制SQL2000的查询分析器,理论上这个方法是可行的,但找不到接口。