program AgentNILM; uses Winapi.Windows, Vcl.Forms, uMain in 'uMain.pas' {fMain}, Vcl.Themes, Vcl.Styles, UMQTTClient in 'UMQTTClient.pas', uLogManagerThread in 'uLogManagerThread.pas', U_DM in 'U_DM.pas' {DM: TDataModule}, uNILMDeviceForm in 'uNILMDeviceForm.pas' {fNILMDevice}, uNILMManager in 'uNILMManager.pas', uNILMTypes in 'uNILMTypes.pas'; {$R *.res} var hMutex: THandle; hPrevWnd: HWND; begin // Mutex를 통한 중복 실행 방지 hMutex := CreateMutex(nil, True, 'Global\AgentNILM_SingleInstance_Mutex'); if (hMutex <> 0) and (GetLastError = ERROR_ALREADY_EXISTS) then begin // 이미 실행 중인 경우 기존 인스턴스 창을 앞으로 가져옴 hPrevWnd := FindWindow('TfMain', nil); if hPrevWnd <> 0 then begin if IsIconic(hPrevWnd) then ShowWindow(hPrevWnd, SW_RESTORE); SetForegroundWindow(hPrevWnd); end else begin MessageBox(0, 'AgentNILM 프로그램이 이미 실행 중입니다.', '알림', MB_OK or MB_ICONINFORMATION); end; CloseHandle(hMutex); Exit; end; try Application.Initialize; Application.MainFormOnTaskbar := True; TStyleManager.TrySetStyle('Tablet Dark'); Application.CreateForm(TfMain, fMain); Application.CreateForm(TDM, DM); Application.Run; finally if hMutex <> 0 then CloseHandle(hMutex); end; end.