⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scheduler.dpr

📁 一個強大的定時服務程序
💻 DPR
字号:
program Scheduler;
{$IFDEF VER150}
{$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_TYPE OFF}
{$ENDIF}
{$IFDEF VER150}
{$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_TYPE OFF}
{$ENDIF}
{$IFDEF VER170}
{$WARN UNSAFE_CAST OFF}
{$WARN UNSAFE_CODE OFF}
{$ENDIF}
uses
  Forms,
  SysUtils,
  windows,
  messages,
  Dialogs,
  Controls,
  Classes,
  IniFiles,
  Main_Unit in 'Main_Unit.pas' {MainForm},
  uCiaServiceTools in 'uCiaServiceTools.pas';

{$R *.res}

var
  hMutex: THandle;
  FoundWnd: THandle;
  ModuleName,ServiceN: string;
  myini:TIniFile;

function EnumWndProc(hwnd: THandle; Param: Cardinal): Bool; stdcall;
var
  ClassName, WinModuleName: string;
  WinInstance: THandle;
begin
  Result := True;
  SetLength(ClassName, 100);
  GetClassName (hwnd, PChar (ClassName), Length (ClassName));
  ClassName := PChar(ClassName);
  if ClassName = TMainForm.ClassName then
  begin
    SetLength(WinModuleName, 200);
    WinInstance := GetWindowLong(hwnd, GWL_HINSTANCE);
    GetModuleFileName (WinInstance, PChar (WinModuleName),
      Length(WinModuleName));
    WinModuleName := PChar(WinModuleName);
    if WinModuleName = ModuleName then
    begin
      FoundWnd := Hwnd;
      Result := False;
    end;
  end;
end;

begin
  myini:=TIniFile.Create(ExtractFilePath(Application.ExeName)+'Setup.ini');
  ServiceN:=myini.ReadString('Setup','service','MyService');
  myini.Free;
  HMutex := CreateMutex(nil, False, PChar(ServiceN));
  if WaitForSingleObject(hMutex, 0) <> WAIT_TIMEOUT then
  begin
    if CiaStartService(ServiceN+'Service') then
    begin
      CiaService.CreateForm(TMainForm, MainForm);
      CiaService.Run;
      Exit;
    end;
    Application.Initialize;
    Application.CreateForm(TMainForm, MainForm);
    Application.Run;
  end
  else
  begin
    SetLength(ModuleName, 200);
    GetModuleFileName (HInstance, PChar(ModuleName), Length (ModuleName));
    ModuleName := PChar(ModuleName);
    EnumWindows(@EnumWndProc, 0);
    if FoundWnd <> 0 then
    begin
      if not IsWindowVisible(FoundWnd) then
        PostMessage(FoundWnd, wm_App, 0, 0);
      SetForegroundWindow(FoundWnd);
    end;
  end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -