線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1509
推到 Plurk!
推到 Facebook!

請問如何控制主程式不被重覆啟動執行?

尚未結案
yuhching
一般會員


發表:10
回覆:9
積分:3
註冊:2004-03-08

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-03-08 21:46:28 IP:211.76.xxx.xxx 未訂閱
請問各位大哥: 如何控制主程式[Main]不被重覆啟動執行?
kevin622
一般會員


發表:0
回覆:22
積分:9
註冊:2003-10-16

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-03-08 21:53:45 IP:210.244.xxx.xxx 未訂閱
program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.RES} var sExeName: string; begin sExeName := ExtractFileName(Application.ExeName); CreateMutex(nil, False, PChar(sExeName)); if GetLastError = ERROR_ALREADY_EXISTS then begin ShowMessage(sExeName '程式已在執行'); Application.Terminate; end; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. §§§ 量力而為 §§§ 當覺得力量不足時,就是該為自己充電的時候了。
yuhching
一般會員


發表:10
回覆:9
積分:3
註冊:2004-03-08

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-03-08 22:51:48 IP:211.76.xxx.xxx 未訂閱
不能編譯,請再幫幫忙! 謝謝!! [Error] Main.dpr(29): Undeclared identifier: 'ExtractFileName' [Error] Main.dpr(30): Undeclared identifier: 'CreateMutex' [Error] Main.dpr(31): Undeclared identifier: 'ERROR_ALREADY_EXISTS' [Error] Main.dpr(32): Undeclared identifier: 'ShowMessage' 發表人 - yuhching 於 2004/03/08 22:56:43
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-03-09 00:19:03 IP:218.15.xxx.xxx 未訂閱
您好,下面有相关的咨询,您试试看 防止程序多次运行 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=33954 相关代码: [dpr部分] program Project1; uses Forms, Unit1 in 'Unit1.pas' {Form1} ,Windows, Messages; const hfck=wm_user $1000; appname='myname'; var myhandle:hwnd; {$R *.res} begin myhandle:=findwindow(appname,nil); if myhandle>0 then begin postmessage(myhandle,hfck,0,0); exit; end; Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; end. [form部分] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; const hfck=wm_user $1000; appname='myname'; type TForm1 = class(TForm) private { Private declarations } public procedure createparams(var params:tcreateparams);override; procedure restorerequest(var msg:tmessage);message hfck; { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.createparams(var params:tcreateparams); begin inherited createparams(params); params.WinClassName:=appname; end; procedure TForm1.restorerequest(var msg:tmessage); begin if isiconic(application.Handle )=true then application.Restore else application.BringToFront ; end; end. 这里也有,您看看 http://delphi.ktop.com.tw/topic.php?topic_id=35983 ——行径窄处,留一步与人行——
yuhching
一般會員


發表:10
回覆:9
積分:3
註冊:2004-03-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-03-09 18:07:56 IP:211.76.xxx.xxx 未訂閱
您好deity ok了 謝謝您
系統時間:2024-06-02 0:12:17
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!