请问高手:
怎样才能使delphi编写的程序生成的可执行程序只能打开一个呢??
即,比如当我打开了一个proxy.exe之后,如果我再想点击打开一个的时候,就让它提示说程序已经在运行,不可以在打开。怎样才能做到呢???
拜托各位帮忙啦,谢谢啦!
怎样才能使delphi编写的程序生成的可执行程序只能打开一个呢??
即,比如当我打开了一个proxy.exe之后,如果我再想点击打开一个的时候,就让它提示说程序已经在运行,不可以在打开。怎样才能做到呢???
拜托各位帮忙啦,谢谢啦!
解决方案 »
- 提取CPU序列号的问题
- [Fatal Error] AACtrls.pas(1): Program or unit 'AACtrls.pas' recursively uses itself
- 为什么老是出错呢??!!晕啊!adoquery问题
- 在delphi里面创建SQL数据库和删除数据库的问题
- 在wise中怎么样使卸载程序也出现在程序菜单中?
- 请问如何在一工程中声明一个公用函数啊?
- 从Delphi到EXCEL的问题,高分请教
- 请问一下delphi是否出了中文版,谁用过?
- 过节了,技术大放送10:用Label显示自己程序的版本。
- 给位兄台!小弟有要事相求!!!!!来者分!!!!!
- 急聘delpi开发人员!
- 我宿舍内设一个服务器win2000 server,自己的,想向网内的客户机发送消息xp,不是所有的都收的到
Forms,windows,
Unit1 in 'Unit1.pas' {Form1};var hw:hwnd;{$R *.RES}
begin
Application.Initialize;
application.title:='test';//名字自己定义
CreateMutex(nil, false, 'ADManager');
if GetLastError <> ERROR_ALREADY_EXISTS then
begin
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
end.
if Hprevinst <> 0 then
begin
ShowMessage('程序已经运行!');
Application.Terminate;
end;
Forms,windows,
Unit1 in 'Unit1.pas' {Form1};var hw:hwnd;{$R *.RES}
Application.Initialize;
mHandle := Windows.CreateMutex(nil, true, 'SendMessage');
if mHandle <> 0 then
begin
if GetLastError = ERROR_ALREADY_EXISTS then
begin
fHandle := FindWindow(PChar('Tfrom1'), nil);
ShowWindow(fHandle, SW_RESTORE);
SetForeGroundWindow(fHandle);
Windows.ReleaseMutex(mHandle);
Halt;
end;
end;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
Hprevinst是什么啊??在formcreate中加入这一段不可以实现好像啊?
cdsgajxlp(新手):
请问,mHandle和fHandle是什么型的?string么??
CreateMutex是个函数么??在help中怎样才能找到它的介绍呢??
Ret:=GetLastError;
if Ret=ERROR_ALREADY_EXISTS Then
begin
ReleaseMutex(hMutex);
ShowMessage('程序已经打开');
end
else
begin
....
Application.Run;
end;
program Project1;uses
Forms,
Windows,
SysUtils,
Unit1 in 'Unit1.pas' {Form1};{$R *.res}Var
hMutex:HWND;
Ret:Integer;
begin
Application.Initialize;
Application.Title := 'aaaaaa';
hMutex:=CreateMutex(nil,False,'aaaaaa');
Ret:=GetLastError;
If Ret<>ERROR_ALREADY_EXISTS Then
Begin
Application.CreateForm(TForm1, Form1);
Application.Run;
End
Else
Application.MessageBox('程序已经运行','Notes!',MB_OK);
ReleaseMutex(hMutex);
end.