没写过多少东西,不知道从何下手,简单的说吧. 1.在dpr文件中引用RunOnce.pas中的Running_EnumWindows过程;整个代码如下: program Yanbin;
uses Forms, main in 'main.pas' {mainfrm}, RunOnce in 'RunOnce.pas';
{$R *.res}
begin Running_EnumWindows; Application.Initialize; Application.Title := '燕冰定时播报系统XP版'; Application.CreateForm(Tmainfrm, mainfrm); Application.NormalizeTopMosts; Application.Run; end. 下面是RunOnce.pas的代码: unit RunOnce;
interface
uses windows,Forms; function EnumApps(Wnd: HWnd;LPARAM: lParam): boolean; stdcall; procedure Running_CreateMutex; procedure Running_FindWindows; procedure Running_EnumWindows; implementation uses main;
function EnumApps(Wnd: HWnd;LPARAM: lParam): boolean; stdcall; var WndCaption : array[0..254] of char; begin Result := True; GetWindowText(Wnd,@WndCaption, 254);//获取窗口的Caption if(Pos('燕冰定时播报系统XP版',WndCaption)>=1)then //如果窗口的Caption含某字符串 begin if IsIconic(Wnd) then //如果已被最小化 begin ShowWindow(Wnd,SW_RESTORE or SW_SHOWNORMAL );//则把它恢复 MessageBox(0,'已经最小化!','提示信息', mb_IconHand); end else //如果窗口被其他窗口遮住,则将它提到前景来 begin application.Restore; application.BringToFront ; // SetForegroundWindow(Wnd); // sendmessage() // MessageBox(0,'提到最前!','提示信息', mb_IconHand); end; flashwindow(wnd,True); Result:=False; Halt; //结束本程序 end; end;
procedure Running_CreateMutex; var MutexHandle: THandle; begin //建立一个用'燕冰定时播报系统XP版'来命名的唯一标记 MutexHandle := CreateMutex(nil, TRUE, '燕冰定时播报系统XP版'); if MutexHandle <> 0 then//如果建立失败, begin //并且错误信息是“唯一标记已存在”,则表明本程序已运行; if GetLastError = ERROR_ALREADY_EXISTS then begin MessageBox(0,'燕冰定时播报系统已经运行!','提示信息', mb_IconHand); CloseHandle(MutexHandle); Halt;//结束本程序 end end; end;
[1] [2] 下一页
|