防止程序重复运行,可以用互斥啊:
//项目文件
...begin
Application.initialation;
if CreateMutex then begin
Application.CreateForm(Form1, TForm1);
Application.Run;
end else
DestroyMutex;
end;//主窗体文件...implementationvar
Mutex: hWnd;function CreateMutex: Boolean;
var
PrevInstHandle: THandle;
AppTitle: PChar;
begin
AppTitle := StrAlloc(100);
StrPCopy(AppTitle, Application.Title);
Result := True;
Mutex := Windows.CreateMutex(nil, False, AppTitle);
if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then begin
Result := False;
SetWindowText(Application.Handle, '');
PrevInstHandle := FindWindow(nil, AppTitle);
if PrevInstHandle <> 0 then begin
if IsIconic(PrevInstHandle) then
ShowWindow(PrevInstHandle, SW_RESTORE)
else
BringWindowToTop(PrevInstHandle);
SetForegroundWindow(PrevInstHandle);
end;
if Mutex <> 0 then
Mutex := 0;
end;
StrDispose(AppTitle);
end;procedure DestroyMutex;
begin
if Mutex <> 0 then
CloseHandle(Mutex);
end;
//项目文件
...begin
Application.initialation;
if CreateMutex then begin
Application.CreateForm(Form1, TForm1);
Application.Run;
end else
DestroyMutex;
end;//主窗体文件...implementationvar
Mutex: hWnd;function CreateMutex: Boolean;
var
PrevInstHandle: THandle;
AppTitle: PChar;
begin
AppTitle := StrAlloc(100);
StrPCopy(AppTitle, Application.Title);
Result := True;
Mutex := Windows.CreateMutex(nil, False, AppTitle);
if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then begin
Result := False;
SetWindowText(Application.Handle, '');
PrevInstHandle := FindWindow(nil, AppTitle);
if PrevInstHandle <> 0 then begin
if IsIconic(PrevInstHandle) then
ShowWindow(PrevInstHandle, SW_RESTORE)
else
BringWindowToTop(PrevInstHandle);
SetForegroundWindow(PrevInstHandle);
end;
if Mutex <> 0 then
Mutex := 0;
end;
StrDispose(AppTitle);
end;procedure DestroyMutex;
begin
if Mutex <> 0 then
CloseHandle(Mutex);
end;
解决方案 »
- qrLabel控件,我的开发环境是简体2000,我想在繁体98下显示,字体是细明体。大家有啥好办法吗?
- DELPHI 控件群赋值
- 求类似于SQL Server的DTS(数据转换向导)的代码或相关信息!
- 一个简单基本的问题求教高手,急在线等
- 浮点问题?
- Beep怎么没有声音?
- 采用什么工具制作中文的CHM格式的帮助文件比较好?
- 请问如何截取win2000信史服务消息的内容 并禁止其弹出MessageBox??
- 有关TClientDataSet的问题
- ~~~~~~~~~~~~~~~to awen800(我本楚狂人) ~~~~~~~~~~~~~
- 怎样设计评卷(试卷含WORD文档)软件
- Delphi中怎样保存断点?家里用Access2000+ADO+delphi,到了学校机房还要手工配置吗(学校只有Access97).
为什么会闪屏?我不是问如何防止程序重复加载