假设有程序a   和检测程序b
1)a程序在运行中,当我打开b时,b就告知用户"a已在运行".
2)b正在运行,当运行a时, b就告知用户"a已在运行"
3)关闭a,  b就告知用户"a已关闭".并记录a的运行时间...我已试过用api截取进程列表,但用这个方法有时会错过,无法正确记录.所以希望各位高手提供更好的方法.谢谢!

解决方案 »

  1.   

    看来a b你都有源代码,可在 a b 中加入udp socket
    定期发状态消息 
      

  2.   

    用DLL内存共享区域试试
    自定义消息也可以
      

  3.   

    1)FindWindow(nil,'a的标题');
    如果返回值不等于0,则a在运行
    2)3)可以参考1),定时检测一下,笨方法...
      

  4.   

    Findwindow这种方法我用过,经常会漏掉检测那个程序的
      

  5.   

    是用查进程
    因为我用Timer每秒检测一次那个窗口是否存在。但经常a关闭了,b还没有察觉
    不知道有无更好的方法
      

  6.   

    给你一个简单的消息通讯的例子:
    程序A:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);
    begin
      if  Msg.CharCode = VK_CONTROL then
        SendMessage(FindWindow(nil,'Form2'), WM_APP+1, 0,0);
    end;
    end.程序B:
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
      public
        procedure WndProc(var Msg: TMessage); override;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.WndProc(var Msg: TMessage);
    begin
     with Msg do
     begin
       if Msg = WM_APP + 1 then
         Form1.Caption := 'gggggg';
     end;
     inherited;
    end;end.
      

  7.   

    这段代码是取得系统所有的进程名: 
    var hCurrentWindow:HWnd;szText:array[0..254] of 
      char;
      begin
      hCurrentWindow:=Getwindow(handle,GW_HWndFrist);
      while hCurrentWindow <> 0 do
      begin
      if Getwindowtext(hcurrnetwindow,@sztext,255)>0 
      then listbox1.items.add(strpas(@sztext));
      hCurrentWindow:=Getwindow(hCurrentwindow,GW_HWndNext);
      end;
      end;楼主可以修改一下,把所有的进程名一一比较是否是a
    另外,也只有定时检测,才能知道a进程是否存在了,如果不能修改a的话.
      

  8.   

    楼上的代码里GW_HWndFrist,hcurrnetwindow这些东东那里有啊?