Skip to content

Commit

Permalink
Activate already running instance instead of showing error message (i…
Browse files Browse the repository at this point in the history
…ssue #36)
  • Loading branch information
artem78 committed Jun 23, 2023
1 parent 121b14f commit 23ee53a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions AutoScreenshot.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions uAutoScreen.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions uAutoScreen.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -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.

0 comments on commit 23ee53a

Please sign in to comment.