请教大家关于在delphi中防止程序多次运行的方法
答案:2 悬赏:70 手机版
解决时间 2021-03-03 06:17
- 提问者网友:记得曾经
- 2021-03-02 10:58
请教大家关于在delphi中防止程序多次运行的方法
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-03-02 11:26
在 delphi 中防止程序多次运行,有多种办法:
1、通过查找是否存在同名窗口的方式来防止,示例代码如下:
Var Hwnd:Thandle;
Begin
Hwnd:=FindWindow(‘窗口类名称’,‘窗口标题’);
If Hwnd=0 then
Begin
Application.Initialize;
Application.CreateForm(Tform1, Form1);
Application.Run;
End;
End;2、使用互斥对象,示例代码如下:
var
mymutex: THandle;
begin
mymutex:=CreateMutex(nil,True,'MyMutx');
if GetLastError<>ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
showmessage('程序已经运行');
end.3、使用全局原子,示例代码如下:
const
myatom='myatom';
begin
if GlobalFindAtom(myatom)=0 then
begin
GlobalAddAtom(myatom);
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
GlobalDeleteAtom(GlobalFindAtom(myatom));
end
else
showmessage('程序已运行');
end.
1、通过查找是否存在同名窗口的方式来防止,示例代码如下:
Var Hwnd:Thandle;
Begin
Hwnd:=FindWindow(‘窗口类名称’,‘窗口标题’);
If Hwnd=0 then
Begin
Application.Initialize;
Application.CreateForm(Tform1, Form1);
Application.Run;
End;
End;2、使用互斥对象,示例代码如下:
var
mymutex: THandle;
begin
mymutex:=CreateMutex(nil,True,'MyMutx');
if GetLastError<>ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
else
showmessage('程序已经运行');
end.3、使用全局原子,示例代码如下:
const
myatom='myatom';
begin
if GlobalFindAtom(myatom)=0 then
begin
GlobalAddAtom(myatom);
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
GlobalDeleteAtom(GlobalFindAtom(myatom));
end
else
showmessage('程序已运行');
end.
全部回答
- 1楼网友:佘樂
- 2021-03-02 12:43
首先你要知道image是从tgraphiccontrol继承的,所以它没有句柄,也设置不了它的doublebuffer。
给你2个建议:
1 窗体上doublebuffer设为true,重载wm_erasebackground这个消息,让他背景不擦出。
2 自己写个控件从tcustomcontrol上面继承下来,然后自己用gdi贴图上去。
闪烁主要还是对画布 绘图太频繁了。
我在csdn上面写了一片文章的。
地址应该是hi.csdn.net/huangjacky.
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯