var
I: Integer;
hMutex: Hwnd;
begin
hMutex:=CreateMutex(nil,false,'Program Run Once Test');
I := GetLastError;
if I = ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(i);
halt;
else
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
end.
I: Integer;
hMutex: Hwnd;
begin
hMutex:=CreateMutex(nil,false,'Program Run Once Test');
I := GetLastError;
if I = ERROR_ALREADY_EXISTS then
begin
ReleaseMutex(i);
halt;
else
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end;
end.
解决方案 »
- 请问一语法问题, 比如 aaa = procedure (i:integer) of object 这是什么意思,举个例子
- 问一个简单的问题,怎样判断网络是否已经断开?
- 求助,如何一运行程序就执行Timer控件中的内容?
- 请大家帮我看看,这是什么问题
- 如何制作MDI窗体,在线等待!
- 这样实现也叫做多线程吗,请大家帮忙参考,进者有分!!!
- clientsocket 编程,(11004),ON API 'ASYNC LOOKUP' 错误 ???
- ADO能否连接DBF文件吗?
- 终于装上KYLIX了,来这里庆祝一下
- 那么delphi程序员的价值呢?
- 如何编程表明是否选中DBGrid表格中的一条记录?求教!
- 线程中涉及到窗体内容为什么总出错?
BOOL bInitialOwner, // flag for initial ownership
LPCTSTR lpName // address of mutex-object name
);参数说明:lpMutexAttributes 此参数指向一个SECURITY_ATTRIBUTES结构,此结构指定该互斥体的安全
属性,如果该参数为NULL(即为空),则以缺省的安全描述符来创建互斥
体,并且该函数返回的句柄不能被继承。
(此参数好象不好理解,不过在此处你只需将其设为NULL就行了!)bInitialOwner 指定互斥体对象的初始拥有者。在此处设为False。lpName 此参数指定互斥体的名字。参数类型是以NULL结尾的字符串。返回值:如果函数成功则返回互斥体的句柄,如果指定的互斥体名已经存在,则GetLastError函数返回
ERROR_ALREADY_EXISTS}
...
Application.Initialize;
Application.Title := '小小音乐家';
hMutex:=CreateMutex(nil,False,'aaaaaa');
Ret:=GetLastError;
if hasrealplayer=1 then begin
if Ret<>ERROR_ALREADY_EXISTS then begin
Application.CreateForm(Tmainform, mainform);
Application.CreateForm(Timageform, imageform);
Application.Run;
end
else
ReleaseMutex(hMutex)
end
...
const
CM_Restore = WM_User + $1000;
AppName = 'Appname'; //自己定义的名,注意要跟工程文件里的名字相同,切记切记
以下两个过程写在主窗体
procedure TMain_Form.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);Params.WinClassName:=AppName;end;procedure TMain_Form.RestoreRequest(var msg: TMessage);
begin
if isIconic(Application.Handle)=True then
Application.Restore
else
Application.BringToFront;
end;在工程文件中按照下面作
const
CM_RESTORE = WM_USER + $1000; {自定义的“恢复”消息}
APPNAME = 'Appname'; //自己的程序名,自己定义即可
var
RvHandle : hWnd;
{$R *.RES}
begin
RvHandle := FindWindow(APPNAME, NIL);
if RvHandle > 0 then
begin
PostMessage(RvHandle, CM_RESTORE, 0, 0);
Exit;
end;
Application.Initialize;
Application.Title := '';
Application.CreateForm(TMain_Form, Main_Form);
Application.Run;
end.