帮我看看如何修改这一段代码(30分)

  • 主题发起人 主题发起人 wzdcli
  • 开始时间 开始时间
W

wzdcli

Unregistered / Unconfirmed
GUEST, unregistred user!
想防止程序重复运行,我在SPLASH(form5.pas)窗体中加入下面代码运行成功。我想在第二次启动程序时能将已经运行的程序恢复到桌面最前,于是加入了application.restore和SetForegroundWindow(Application.MainForm.Handle),但程序并有提到最前面。请哪位帮忙搞定,谢谢。(我还使用了托盘控件,最小化时会缩小到托盘,显示窗体用icon.showmainform)<br>form5.pas:<br>&nbsp;var MutexHandle: Thandle;<br>begin<br>&nbsp;Mutexhandle := windows.CreateMutex(nil, true, 'project');<br>if Mutexhandle &lt;&gt; 0 then<br>&nbsp;begin<br>&nbsp; &nbsp;if getlasterror = windows.ERROR_ALREADY_EXISTS then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; Application.MessageBox('程序已经运行!', '提示', 48);<br>&nbsp; &nbsp; closehandle(Mutexhandle);<br>&nbsp; &nbsp; &nbsp;halt;<br>&nbsp; &nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;end; <br><br>我看到有些人在项目文件里修改,我试过也没成功,下面是我的项目文件:<br><br>{$R *.res}<br>begin<br>&nbsp; Application.Initialize;<br>&nbsp; form5:=Tform5.Create(Application); //form5为splash窗口<br>&nbsp; form5.ShowModal;<br>&nbsp; if (form5.modalresult=mrOk) then<br>&nbsp; begin<br>&nbsp; Application.Title := '管理软件';<br>&nbsp; Application.CreateForm(Tform1, form1);//form1为主窗口<br>end.
 
begin<br>&nbsp; Application.Initialize;<br>&nbsp; form5:=Tform5.Create(Application); //form5为splash窗口<br>&nbsp; form5.Show;<br>&nbsp; form5.update;<br>&nbsp; if (form5.modalresult=mrOk) then<br>&nbsp; begin<br>&nbsp; Application.Title := '管理软件';<br>&nbsp; Application.CreateForm(Tform1, form1);//form1为主窗口<br>&nbsp; form5.hide;<br>&nbsp; Form5.Free;<br>&nbsp;Application.Run;<br>end. &nbsp;
 
来自:liuchengr, 时间:2004-3-1 22:35:32, ID:2479386<br>如何让程式只执行一份? <br>整理编辑:China ASP<br><br>program DEL3test;<br><br>uses<br>Forms,Windows,SysUtils,<br>DEL3unit in 'DEL3unit.pas' {Form1};<br><br>{$R *.RES}<br><br>Var<br>hMutex:HWND;<br>Ret:Integer;<br>begin<br>Application.Initialize;<br>Application.Title := 'aaaaaa';<br>hMutex:=CreateMutex(nil,False,'aaaaaa');<br>Ret:=GetLastError;<br>If Ret&lt;&gt;ERROR_ALREADY_EXISTS Then <br>Begin<br>Application.CreateForm(TForm1, Form1);<br>Application.Run;<br>End<br>Else<br>Application.MessageBox('Run Twice!','Notes!',MB_OK);<br>ReleaseMutex(hMutex);<br>end.<br><br><br>加入时间:2000-5-1<br>阅<br>
 
上面的老兄还是不对啊
 
哪儿不对。<br>begin<br>&nbsp; Application.Initialize;<br>&nbsp; form5:=Tform5.Create(Application); //form5为splash窗口<br>&nbsp; form5.Show;///<br>&nbsp; if (form5.modalresult=mrOk) then<br>&nbsp; begin<br>&nbsp; Application.Title := '管理软件';<br>&nbsp; Application.CreateForm(Tform1, form1);//form1为主窗口<br>&nbsp;end;///<br>end. &nbsp;
 
我用了托盘控件后不能将已运行的程序提到桌面最前面
 
自己解决了。但还是将分送给好心帮助的人。
 
后退
顶部