Ignore:
Timestamp:
Aug 1, 2016, 1:10:13 PM (8 years ago)
Author:
chronos
Message:
  • Added: Allow to configure application to start automatically on user logon and start minimized to tray.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r69 r70  
    136136  public
    137137    AcronymDb: TAcronymDb;
     138    StartOnLogon: Boolean;
     139    StartMinimizedToTray: Boolean;
    138140    function CompareStrings(Strings1, Strings2: TStrings): Boolean;
    139141    property AlwaysOnTop: Boolean read FAlwaysOnTop write SetAlwaysOnTop;
     
    165167  DefaultFileName = 'Acronyms' + ProjectExt;
    166168  DefaultRegKey = '\Software\Acronym Decoder';
     169  RegistryRunKey = '\Software\Microsoft\Windows\CurrentVersion\Run';
     170  ExampleFile = 'Example acronyms.adp';
    167171
    168172{ TFormMain }
     
    305309begin
    306310  FormSettings.Load;
    307   if FormSettings.ShowModal = mrOk then
     311  if FormSettings.ShowModal = mrOk then begin
    308312    FormSettings.Save;
     313    SaveConfig;
     314  end;
    309315end;
    310316
     
    456462    LoadConfig;
    457463
     464    if StartMinimizedToTray then Visible := False;
     465
    458466    if ParamCount > 0 then begin
    459467      // Open file specified as command line parameter
     
    466474    end else begin
    467475      // Open default database with examples if no item is in recent openned history
    468       ProjectOpen(ExtractFileDir(Application.ExeName) + DirectorySeparator + 'Example Acronyms.adp');
     476      ProjectOpen(ExtractFileDir(Application.ExeName) + DirectorySeparator + ExampleFile);
    469477    end;
    470478    UpdateAcronymsList;
     
    590598      else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    591599    AlwaysOnTop := ReadBoolWithDefault('AlwaysOnTop', False);
     600    StartMinimizedToTray := ReadBoolWithDefault('StartMinimizedToTray', False);
    592601    CheckBoxExactMath.Checked := ReadBoolWithDefault('ExactMatch', False);
    593602    MenuItemToolbar.Checked := ReadBoolWithDefault('ToolBarVisible', True);
     603  finally
     604    Free;
     605  end;
     606
     607  with TRegistryEx.Create do
     608  try
     609    RootKey := HKEY_CURRENT_USER;
     610    OpenKey(RegistryRunKey, True);
     611    StartOnLogon := ValueExists('Acronym Decoder');
    594612  finally
    595613    Free;
     
    610628      else DeleteValue('LanguageCode');
    611629    WriteBool('AlwaysOnTop', AlwaysOnTop);
     630    WriteBool('StartMinimizedToTray', StartMinimizedToTray);
    612631    WriteBool('ExactMatch', CheckBoxExactMath.Checked);
    613632    WriteBool('ToolBarVisible', MenuItemToolbar.Checked);
     
    615634    Free;
    616635  end;
     636
     637  with TRegistryEx.Create do
     638  try
     639    RootKey := HKEY_CURRENT_USER;
     640    OpenKey(RegistryRunKey, True);
     641    if StartOnLogon then WriteString('Acronym Decoder', Application.ExeName)
     642      else DeleteValue('Acronym Decoder');
     643  finally
     644    Free;
     645  end;
    617646end;
    618647
Note: See TracChangeset for help on using the changeset viewer.