最好是有所提示
解决方案 »
- 运行的时候提示 变量没有被用过 是为什么?
- DBComboBox还是不能显示所有信息?
- //----------------IdFtp获取服务器文件Size的问题--------------------//
- 我想往FORM里写一些软件说明的文字,字挺多的,我不知道是用LABEL还是MEMO?
- 这种效果是怎么做出来的?
- 如何通过判断PageControl的标签页的焦点,来选择不同的语句?
- BDE别名,嘻~
- Form.Canvas这个画布属性可以显示任何文件类型吗?
- 我的Delphi6出现一个怪现象:编译错误提示条不是出现在真正出错的地方!哪位给个理由?
- 怎么通过计算机名得到其所在的工作组!!(是好答案,我一定马上给分)
- @@@@如何完成UNICODE码到区位码的转换(给出提示20分,给出函数50分,给出源程序200分)
- 请问:关于word自动化的问题
有很多的办法
你可以做一个自己定义一个全局变量,程序执行到那时赋值给false,
而当下一次使用时判断,这个变量是否为Fasle .就可以了。
begin
//程序只运行一次
CreateMutex(Nil, true, 'DGEKDsswW');//创建一个标记
if GetLastError <> ERROR_ALREADY_EXISTS then
begin
Application.Initialize;
//……Form窗体的创建
Application.Run;
end
else
//自己的提示
end.
hMutex : Thandle;
WaitResult : word;
BroadcastList : DWORD;
begin
MessageID := RegisterWindowMessage('Check For Choice Previous Inst');
// register a message to use later on
hMutex := createMutex(nil,false,pchar('App_Choice')); // grab a mutex
handle
WaitResult := WaitForSingleObject(hMutex,10); // wait to see
if we can have exclusive use of the mutex
if ( waitResult = WAIT_TIMEOUT ) then // if we can't then broadcast
the message to make the owner of the mutex respond { request that the running application takes focus }
begin
BroadcastList := BSM_APPLICATIONS;
BroadcastSystemMessage(
BSF_POSTMESSAGE,@BroadcastList,MessageID,0,0); //32 bit - broadcast the
message to all apps - only a prev inst will hear it.
end
else
begin
{ do the normal stuff}
Application.Title := 'Choice Organics Purchase & Sales System';
Application.CreateForm(TMainForm, MainForm);
Application.Run;
ReleaseMutex(hMutex); // release the mutex as a politeness end;
CloseHandle(hMutex); // close the mutex handle
end.This goes in the MainFormprocedure Tmainform.OnAppMessage(var Msg : TMsg ; Var Handled : Boolean);
begin
{ If it's the special message then focus on this window}
if Msg.Message = MessageID then // if we get the broadcast message from an
another instance of this app that is trying to start up
begin
show;
WindowState := wsMaximized;
BringToFront;
SetFocus;
Handled := true; end;
end;//And this goes in the TMainForm.FormCreate ;-Application.OnMessage:= OnAppMessage;
在工程文件中const classname='TfmMainMMS'; {声明为主窗体的类名}
var handle:integer; {变量}begin
handle:=findwindow(classname,nil);{查找是否有此类的窗体}
if handle<>0 then {不为0则程序已运行}
begin
messagebox(0,#13+' 综合市场计算机信息管理系统已经运行! '+#13,'综合市场',0);{提示程序已运行}
halt; {退出程序}
end;
var handle:integer; {变量}begin
handle:=findwindow(classname,nil);{查找是否有此类的窗体}
if handle<>0 then {不为0则程序已运行}
begin
messagebox(0,#13+' 综合市场计算机信息管理系统已经运行! '+#13,'综合市场',0);{提示程序已运行}
halt; {退出程序}
end; Application.Initialize;
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.
程序运行时会进行“根据窗体类名查找窗口句柄”操作,找到了将那个程序
设为前台,并关闭自已,
如没找到,则继续运行。也就是实现一个程序只能运行 一个实例,这是一个基本的向别的程序发消息的例子
begin
Application.MainForm.WindowState := wsNormal;
Application.Restore;
end;
SetForegroundWindow(Application.MainForm.Handle);
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.
程序运行时会进行“根据窗体类名查找窗口句柄”操作,找到了将那个程序
设为前台,并关闭自已,
如没找到,则继续运行。也就是实现一个程序只能运行 一个实例,这是一个基本的向别的程序发消息的例子
implementation
var hnd: THandle;initialization
hnd := CreateMutex(nil, True, 'irgendwaseinmaliges');
if GetLastError = ERROR_ALREADY_EXISTS then Halt;finalization
if hnd <> 0 then CloseHandle(hnd);
end.
在uses下加window;
begin
if(FindWindow(nil,'广东省出口发票管理系统——用户登陆')<>0)then
//引号里的中文是你程序主界面的caption;
Application.MessageBox('已经有一个实例','警告',MB_OK)
else
begin
Application.Initialize;
Application.CreateForm(TDengLuForm1, DengLuForm1);
Application.CreateForm(TExportform, Exportform);
Application.CreateForm(TTianKaiForm, TianKaiForm);
Application.CreateForm(TTongJiForm1, TongJiForm1);
Application.CreateForm(TCaXunform, CaXunform);
Application.CreateForm(TKeHuGUanliForm1, KeHuGUanliForm1);
Application.CreateForm(TCaXunForm1, CaXunForm1);
Application.CreateForm(Txitongweihuform, xitongweihuform);
Application.CreateForm(TFaPiaoChaXunForm1, FaPiaoChaXunForm1);
Application.CreateForm(TQingkuangTongJiForm1, QingkuangTongJiForm1);
Application.CreateForm(TCopia_Dbf, Copia_Dbf);
Application.CreateForm(THuiFuform, HuiFuform);
Application.Run;
end;
end;
var
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;
Application.Initialize;
Application.CreateForm(TDengLuForm1, DengLuForm1);
Application.CreateForm(TExportform, Exportform);
Application.CreateForm(TTianKaiForm, TianKaiForm);
Application.CreateForm(TTongJiForm1, TongJiForm1);
Application.CreateForm(TCaXunform, CaXunform);
Application.CreateForm(TKeHuGUanliForm1, KeHuGUanliForm1);
Application.CreateForm(TCaXunForm1, CaXunForm1);
Application.CreateForm(Txitongweihuform, xitongweihuform);
Application.CreateForm(TFaPiaoChaXunForm1, FaPiaoChaXunForm1);
Application.CreateForm(TQingkuangTongJiForm1, QingkuangTongJiForm1);
Application.CreateForm(TCopia_Dbf, Copia_Dbf);
Application.CreateForm(THuiFuform, HuiFuform);
Application.Run;
var
MutexHandle:THandle;
hPrevInst:Boolean;
begin
MutexHandle := CreateMutex(nil, True, 'AppMutex');
if MutexHandle <> 0 then begin
if GetLastError= ERROR_ALREADY_EXISTS then begin
hPrevInst := True;
CloseHandle(MutexHandle);
Halt;
end else begin
hPrevInst := FALSE;
end;
end else begin
hPrevInst := FALSE;
end;
end;