1,184
社区成员
发帖
与我相关
我的任务
分享var
local_mutexhal: THandle;
begin
local_mutexhal := OpenMutex(MUTEX_ALL_ACCESS, FALSE, 'Run1');
if local_mutexhal<> 0 then //
begin
CloseHandle(local_mutexhal);
ShowMessage('对不起,此程序已运行'+IntToStr(GetLastError));
end;
end;
////先定义了一个全局句柄mutexhal
procedure TForm1.Button2Click(Sender: TObject);
var
i,sum:integer;
begin
sum:=1;
mutexhal := CreateMutex(nil, TRUE, 'Run1');
for i:=0 to 1000 do
begin
sum:=sum+i;
label1.Caption :=inttostr(sum);
Application.ProcessMessages;
sleep(1);
end;
ReleaseMutex(mutexhal);
CloseHandle(mutexhal);
exit;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hpa,hc:HWND;
begin
if OpenMutex(MUTEX_ALL_ACCESS, FALSE, 'Run1') <> 0 then //
begin
ShowMessage('对不起,些程序已运行');
end;
//hpa:=Findwindow(nil,Pchar('form2'));
//hc:=FindWindowEx(hpa,0,nil,Pchar('button1'));
//SendMessage(hpa,WM_COMMAND,BN_CLICKED,hc);
//label1.Caption :='??????? !!!!';
end;
//先定义了一个全局句柄mutexhal
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenMutex(MUTEX_ALL_ACCESS, FALSE, 'Run1') <> 0 then
begin
ShowMessage('对不起,Button2在运行');
Exit;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i,sum:integer;
begin
mutexhal := CreateMutex(nil, TRUE, 'Run1');
sum:=1;
for i:=0 to 1000 do
begin
sum:=sum+i;
label1.Caption :=inttostr(sum);
Application.ProcessMessages;
end;
ReleaseMutex(mutexhal);
exit;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
hMutex: THandle;
begin
hMutex := CreateMutex(nil, True, 'Run1');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('对不起,Button2在运行');
Exit;
end
else
begin
if hMutex <> 0 then
begin
ReleaseMutex(hMutex);
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
CreateMutex(nil, True, 'Run1');
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessage('对不起,Button2在运行');
Exit;
end;
end;