怎么使程序退出呀!!!!能检测到程序一运行了,但程序弹出一个窗口后还是运行了,怎么不实现推出呀!!(在线等!!)(0分)

  • 主题发起人 主题发起人 cntiny
  • 开始时间 开始时间
C

cntiny

Unregistered / Unconfirmed
GUEST, unregistred user!
我用procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong (Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
RegisterServiceProcess(0,RSP_SIMPLE_SERVICE);
////
if OpenMutex(MUTEX_ALL_ACCESS,True,'Projectabc')>0 then
begin
MessageBox(0,'程序已经在运行','错误',MB_OK);
end
else
begin
CreateMutex(nil,True,'Projectabc');
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
CloseHandle(OpenMutex(MUTEX_ALL_ACCESS,True,'Projectabc'));
end;
/////
end;


能检测到程序一运行了,但程序弹出一个窗口后还是运行了,怎么不实现推出呀!!
 
要在.dpr文件中改,注意是dpr,就是那个工程文件,举个例子:
program IETool;
uses
Forms,
Windows,
Main in 'Main.pas' {frmMain};
var
hMutex:hwnd;
ret:integer;
{$R *.res}
begin
Application.Initialize;
// run only once---------------------------------------
hMutex:=CreateMutex(nil,false,'project1');
ret:=GetLastError;
if ret=ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(hMutex);
MessageBox(Application.Handle,'抱歉,本程序已经在运行!','收藏伴侣' ,
MB_OK + MB_DEFBUTTON1 + MB_ICONEXCLAMATION);
exit;
end;
//-----------------------------------------------------
Application.CreateForm(TfrmMain, frmMain);
Application.ShowMainForm := false;
//Hide Main form, IE toolvar version.
Application.Run;
end.
 
谢谢了大哥!!!
感激不尽!!
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
622
import
I
后退
顶部