if WaitForSingleObject(myMutex,0)<>wait_TimeOut then//程序没有被运行过
但程序打开后自动关闭了。
...全文
3788打赏收藏
如何程序互斥,只打开一次?
我是这样写的。 var myMutex:HWND; begin myMutex:=CreateMutex(nil,false,'myCopy');// CreateMutex建立互斥对象,并且给互斥对象起一个唯一的名字。 if WaitForSingleObject(myMutex,0)wait_TimeOut then//程序没有被运行过 但程序打开后自动关闭了。
Application.Initialize;
application.title:='HighSoftClient';
tmp:=createmutex(nil,false,'HighSoftClient');
if getlasterror<>error_already_exists then
begin
Application.CreateForm(TMainFrm, MainFrm);
Application.Run;
end;
这样可以使你的程序只运行一次