有没有函数可以判断文件是否被打开我就不知道,但我想如果<br>用互斥对象来进行检查应该可以行得通,在这里我提供一个<br>程序给你,该程序是用于使程序只运行一次的<br>unit Unit1; <br>interface <br>uses <br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br><br>type <br> TForm1 = class(TForm) <br> private <br> { Private declarations } <br> public <br> { Public declarations } <br> end; <br><br>var <br> Form1: TForm1; <br> mHandle: THandle; <br>// 保存Mutex句柄 <br> PreviousInstanceWindow:HWND; <br> Project: string; <br> AppName:string; <br><br>implementation <br><br>{$R *.DFM} <br>initialization <br> Project := 'RunOnlyOnce_MyProject'; <br>//此处定义自己的项目名称,作为要创建的互斥区名,最好有自己特点已防止重复 <br> mHandle := CreateMutex(nil, True, PChar(Project)); <br> // lpMutexAttributes设为nil,bInitialOwner设为True(即本程序拥有该互斥区) <br> if GetLastError = ERROR_ALREADY_EXISTS then <br> //该互斥区已存在则表明已有本程序的另一个实例在运行 <br> begin <br> showmessage('已经有该程序的一个实例在运行'); <br> AppName:=Application.Title; <br> //保存程序标题 <br> Application.ShowMainForm := false; <br> //不显示本窗口 <br> Application.Title := 'destroy me'; <br> //改变程序标题,以使FindWindow找到的是前一个实例窗口 <br> PreviousInstanceWindow := FindWindow(nil,pchar(AppName)); <br> //寻找前一个实例窗口句柄 <br> if PreviousInstanceWindow <> 0 then <br> //已经找到 <br> if IsIconic(PreviousInstanceWindow) then <br> //如该窗口最小化则恢复 <br> ShowWindow(PreviousInstanceWindow,SW_RESTORE) <br> else <br> SetForegroundWindow(PreviousInstanceWindow); <br> //否则如程序在后台则将其放到前台 <br> Application.Terminate; <br> //中止本实例 <br> end; <br><br>finalization <br> if mHandle <> 0 then <br> //该互斥区对象仍存在则关闭对象 <br> CloseHandle(mHandle); <br>end. <br>将上面的程序改成你的文件,试试看