防止程序多次运行

2008-04-11 12:26:53来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

网络ID:wnhoo or sos_admin
网名:e梦缘
Mail:wnhoo@163.com
风花雪月 e梦情缘

http://delphi.ur-solution.com/delphi_download/upload/33954_wnhoo.rar

[dpr部分]
program Project1;

uses
Forms,
Unit1 in ''''Unit1.pas'''' {Form1}
,Windows, Messages;

const
hfck=wm_user $1000;
appname=''''myname'''';
var
myhandle:hwnd;
{$R *.res}

begin
myhandle:=findwindow(appname,nil);
if myhandle>0 then
begin
postmessage(myhandle,hfck,0,0);
exit;
end;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

[form部分]
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
const
hfck=wm_user $1000;
appname=''''myname'''';
type
TForm1 = class(TForm)
private
{ Private declarations }
public
procedure createparams(var params:tcreateparams);override;
procedure restorerequest(var msg:tmessage);message hfck;


{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.createparams(var params:tcreateparams);
begin
inherited createparams(params);
params.WinClassName:=appname;
end;
procedure TForm1.restorerequest(var msg:tmessage);
begin
if isiconic(application.Handle )=true then
application.Restore
else
application.BringToFront ;

end;
end.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:关于流的使用资料及相关实例

下一篇:將字串传入到Windows目前窗口Cursor所在位置