假设有程序a 和检测程序b
1)a程序在运行中,当我打开b时,b就告知用户"a已在运行".
2)b正在运行,当运行a时, b就告知用户"a已在运行"
3)关闭a, b就告知用户"a已关闭".并记录a的运行时间...我已试过用api截取进程列表,但用这个方法有时会错过,无法正确记录.所以希望各位高手提供更好的方法.谢谢!
1)a程序在运行中,当我打开b时,b就告知用户"a已在运行".
2)b正在运行,当运行a时, b就告知用户"a已在运行"
3)关闭a, b就告知用户"a已关闭".并记录a的运行时间...我已试过用api截取进程列表,但用这个方法有时会错过,无法正确记录.所以希望各位高手提供更好的方法.谢谢!
解决方案 »
- delphi中怎么在DBgrid中实现鼠标滚轮效果?
- 请教QREPORT调试的问题。在线等!!!!!!!!!!!!
- 如何控制在dbgrideh中会车键焦点的移动方向?
- ADODataSet.Insert和ADODataSet.Append有什么区别?
- 关于添加组件的几种方式
- 为什么ADOTable控件的Active一设为True就报错?
- 怎样才能使treeview的selected定位在刚增加的项上
- 哪个网站有有关delphi的英语文章???
- dxBarManager style 问题
- :◆◇◆◇◆◇对CSDN各网友严重警告◇◆◇◆◇◆--------------Delphi版块
- 求一套正规软件开发项目的所有相关文档 最好是DELPHI数据库方面的
- 做过POS打印程序的高手快进来,高分求救
定期发状态消息
自定义消息也可以
如果返回值不等于0,则a在运行
2)3)可以参考1),定时检测一下,笨方法...
因为我用Timer每秒检测一次那个窗口是否存在。但经常a关闭了,b还没有察觉
不知道有无更好的方法
程序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.
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的话.