var
ret:integer;
if ret = Error_ALREADY_EXISTS then
Application.MessageBox('系统已在运行!','提示',mb_OK);
ret:integer;
if ret = Error_ALREADY_EXISTS then
Application.MessageBox('系统已在运行!','提示',mb_OK);
解决方案 »
- Delphi 如何判断密码不能小于8位。。。。。
- delphi在DCOM的客户端连上中间服务器后,怎样实现多表操作的事务控制
- TstringList里面的内容按降序排列
- 寻求一个函数!
- 如何判断SQL server2000里的一个表是否存在?如何按月建表?如何在按月分表的数据库中跨月查询数据?
- 关于中国互动游戏中心所使用的协议和端口?
- 怎么动态快速设置窗口上数据集都只能看,不能修改!?
- (新!新!新!)如何找回不能打开硬盘分区中的数据?
- 刚刚遇到的一个新问题.
- 各位大侠,请问怎么把BDE打包进去?
- TQuery 控件的SQL属性不能输入字母,只能输入数字,重装DELPHI也不行是不是一定要重装WINDOWS啊?
- 请问能否把DELPHI中的报表预览控件改成Stayontop,即只能响应给控件后,才能做其它操作?
Forms,Windows,Messages,
FRM_AUTORUN in 'FRM_AUTORUN.pas' {LOGO};
const// 自定义一个消息,用来恢复窗口
CM_RESTORE=WM_USER+$1000;
APPNAME='安装程序';
VAR RvHandle:hWnd;
{$R *.RES}
begin
RvHandle :=FindWindow(APPNAME, NIL); // 根据窗体类名查找窗口句柄
if RvHandle > 0 then // 如果找到则发送自定义的消息并退出
begin
PostMessage(RvHandle,CM_RESTORE,0,0);
SetForegroundWindow(RvHandle);
exit;
end ;
Application.Initialize;
Application.Title := '网络版安装引导界面';
Application.CreateForm(TLOGO, LOGO);
Application.Run;
end.
/////////////////////////////////////////////////////unit FRM_AUTORUN;interfaceuses
Windows,Forms,jpeg,Controls, StdCtrls, ExtCtrls, Classes,Messages,
shellapi, SysUtils;
const// 自定义一个消息,用来恢复窗口
CM_RESTORE=WM_USER+$1000;
APPNAME='安装程序';
type
TLOGO = class(TForm)
private
{ Private declarations } public
{ Public declarations }
procedure CreateParams(var Params: TCreateParams); override;
Procedure RestoreRequest(var message: TMessage); message CM_RESTORE ;
end;var
LOGO: TLOGO;implementation{$R *.DFM}
procedure Tlogo.CreateParams(var Params: TCreateParams);
begin
// 设置窗体的类名
inherited CreateParams(Params);
Params.WinClassName := APPNAME;
end ;procedure Tlogo.RestoreRequest(var message: TMessage);
begin
// 接到自定义的消息后,如果处于最小化状态则恢复,否则放置到桌面的最前面
//messageBox (Handle , '程序" ' + APPNAME+ ' "已经运行了。' ,'信息' , MB_OK + MB_ICONINFORMATION + MB_SYSTEMMODAL) ;
if IsIconic(Application.Handle) = TRUE then
Application.Restore
else
Application.BringToFront;
end;
end.
程序运行时会进行“根据窗体类名查找窗口句柄”操作,找到了将那个程序
设为前台,并关闭自已,
如没找到,则继续运行。也就是实现一个程序只能运行 一个实例,
var
//避免程序的二次运行;
h: HWND;
begin
Application.Initialize;
h := FindWindowEx(0, 0, 'TApplication', '管理系统');
if h <> 0 then Application.Terminate;
Application.Title := '管理系统'; Application.Title := '管理系统';
Application.CreateForm(TMianForm, MianForm);
LoginForm.Free;
Application.Run;
begin
Mutex := CreateMutex(nil, True, 'SingleApp'); //SingleApp,一个比较特殊的名字
if GetLastError <> ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
end;
begin
hMutex := OpenMutex(MUTEX_ALL_ACCESS, True, 'YourString');
if hMutex <> 0 then Exit;
hMutex := CreateMutex(nil, False, 'BambooChatHotKey');
if hMutex = 0 then Exit;
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex(hMutex);
end;
end.
begin
hMutex := OpenMutex(MUTEX_ALL_ACCESS, True, 'YourString');
if hMutex <> 0 then Exit;
hMutex := CreateMutex(nil, False, 'BambooChatHotKey');
if hMutex = 0 then Exit;
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex(hMutex);
end;
end.
begin
hMutex := OpenMutex(MUTEX_ALL_ACCESS, True, 'YourString');
if hMutex <> 0 then Exit;
hMutex := CreateMutex(nil, False, 'BambooChatHotKey');
if hMutex = 0 then Exit;
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex(hMutex);
end;
end.
var hMutex: THandle;
begin
hMutex := OpenMutex(MUTEX_ALL_ACCESS, True, 'YourString');
if hMutex <> 0 then Exit;
hMutex := CreateMutex(nil, False, 'YourString');
if hMutex = 0 then Exit;
try
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
finally
ReleaseMutex(hMutex);
end;
end.