From 23ee53a55535d741507eb962049db85fa98ffd59 Mon Sep 17 00:00:00 2001 From: artem78 Date: Sat, 24 Jun 2023 00:18:03 +0300 Subject: [PATCH] Activate already running instance instead of showing error message (issue #36) --- AutoScreenshot.lpr | 4 ++-- uAutoScreen.lfm | 7 +++++++ uAutoScreen.pas | 13 +++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/AutoScreenshot.lpr b/AutoScreenshot.lpr index 8f1d159..d52792c 100644 --- a/AutoScreenshot.lpr +++ b/AutoScreenshot.lpr @@ -27,9 +27,9 @@ //setHeapTraceOutput('trace.log'); // Prevent to run second instance - if InstanceRunning('AutoScreenshot') then + if InstanceRunning('AutoScreenshot', True) then begin - Application.MessageBox('Another instance is running!', 'Error', MB_ICONERROR + MB_OK); + //Application.MessageBox('Another instance is running!', 'Error', MB_ICONERROR + MB_OK); Application.Terminate; Exit; end; diff --git a/uAutoScreen.lfm b/uAutoScreen.lfm index dc88789..b77cd4c 100755 --- a/uAutoScreen.lfm +++ b/uAutoScreen.lfm @@ -596,4 +596,11 @@ object MainForm: TMainForm end end end + object UniqueInstance1: TUniqueInstance + Enabled = True + Identifier = 'AutoScreenshot' + OnOtherInstance = UniqueInstance1OtherInstance + Left = 547 + Top = 105 + end end diff --git a/uAutoScreen.pas b/uAutoScreen.pas index d395784..d9ebc6b 100755 --- a/uAutoScreen.pas +++ b/uAutoScreen.pas @@ -13,8 +13,8 @@ interface {$EndIf} {Messages,} SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, {ComCtrls,} ExtCtrls, StdCtrls, inifiles, Spin, {FileCtrl,} - Menus, Buttons, EditBtn, uLocalization, DateTimePicker, - LCLIntf, ScreenGrabber, uHotKeysForm, uUtilsMore, GlobalKeyHook, + Menus, Buttons, EditBtn, uLocalization, DateTimePicker, LCLIntf, + ScreenGrabber, uHotKeysForm, uUtilsMore, GlobalKeyHook, UniqueInstance, ZStream { for Tcompressionlevel }; type @@ -78,6 +78,7 @@ TMainForm = class(TForm) SeqNumberValueSpinEdit: TSpinEdit; SeqNumberDigitsCountSpinEdit: TSpinEdit; SeqNumberDigitsCountLabel: TLabel; + UniqueInstance1: TUniqueInstance; procedure CheckForUpdatesMenuItemClick(Sender: TObject); procedure AutoCheckForUpdatesMenuItemClick(Sender: TObject); procedure CompressionLevelComboBoxChange(Sender: TObject); @@ -115,6 +116,8 @@ TMainForm = class(TForm) procedure TrayIconDblClick(Sender: TObject); procedure SeqNumberValueSpinEditChange(Sender: TObject); procedure SeqNumberDigitsCountSpinEditChange(Sender: TObject); + procedure UniqueInstance1OtherInstance(Sender: TObject; + ParamCount: Integer; const Parameters: array of String); private { Private declarations } @@ -1720,4 +1723,10 @@ procedure TMainForm.SeqNumberDigitsCountSpinEditChange(Sender: TObject); end; end; +procedure TMainForm.UniqueInstance1OtherInstance(Sender: TObject; + ParamCount: Integer; const Parameters: array of String); +begin + RestoreFromTray; +end; + end.