home *** CD-ROM | disk | FTP | other *** search
/ PC Administrator / spravce.iso / StartRight / source / UnitFrmDummyRunner.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-26  |  3.5 KB  |  137 lines

  1. unit UnitFrmDummyRunner;
  2. {
  3.     Purpose:
  4.         This form controls the startup process by creating/removing
  5.         the system tray icon and running the behind the sense processes.
  6.  
  7.     Updates:
  8.         Icon notification for new items and double click will open the Edit
  9.         form and hilight new itesm        
  10. }
  11.  
  12. interface
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  16.   Dialogs,  ShellAPI,
  17.   UnitStartupMover, UnitStartupRunner, ImgList;
  18.  
  19. const MY_WM_TRAYICON = WM_USER + 1; // used to receive tray icon messsages
  20. type
  21.   TfrmDummyRunner = class(TForm)
  22.     ImageList1: TImageList;
  23.     procedure FormDestroy(Sender: TObject);
  24.     procedure FormCreate(Sender: TObject);
  25.   private
  26.     { Private declarations }
  27.         sm : TStartupMover;
  28.         sr : TStartupRunner;
  29.         TrayIcon: TNotifyIconData;          {tray icon info}
  30.          procedure WMTrayIcon(var Msg: TMessage); message MY_WM_TRAYICON;
  31.   public
  32.     { Public declarations }
  33.         procedure DoYourThing;
  34.   end;
  35.  
  36. var
  37.   frmDummyRunner: TfrmDummyRunner;
  38.  
  39. implementation
  40.  
  41. Uses UnitFormEdit, UnitRegistryManager;
  42.  
  43. {$R *.dfm}
  44.  
  45. procedure TFrmDummyRunner.DoYourThing;
  46. var icon : TIcon;
  47. begin
  48.     sm := TStartupMover.Create(self.Handle);
  49.     sr := TStartupRunner.Create(self.Handle);
  50.  
  51.     //
  52.     // Create System Tray Icon
  53.     //
  54.     TrayIcon.cbSize := SizeOf(TrayIcon);
  55.     TrayIcon.Wnd := Self.Handle;
  56.     TrayIcon.uID := 0;
  57.     TrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
  58.     TrayIcon.uCallbackMessage := 0;
  59.     TrayIcon.hIcon := Application.Icon.Handle;
  60.     TrayIcon.szTip := 'StartRight';
  61.     ShellAPI.Shell_notifyIcon(NIM_ADD, @TrayIcon);
  62.  
  63.  
  64.     Windows.Sleep(5000);
  65.     // copy new stuff, run everything
  66.     //
  67.     // NOTE: The autoexcluder will check for duplicate entries
  68.     // in my startup locations, and windows locations that may
  69.     // have occured after the last time StartRight was run.
  70.  
  71.     {AutoExcluder.Run;}
  72.     RegistryManager.AutoExcludeRunkeyItems;
  73.     RegistryManager.AutoExcludeStartupItems;
  74.  
  75.     sm.MoveRunKeyItems;
  76.     sm.MoveStartupFolderItems;
  77.     sr.ExecuteRunkeyPrograms;
  78.     sr.ExecuteStartupFolderPrograms;
  79.  
  80.  
  81.  
  82.     //
  83.     // Remove tray icon
  84.     //
  85.     ShellAPI.Shell_notifyIcon(NIM_DELETE, @TrayIcon);
  86.  
  87.     //
  88.     // show the 'New Items' icon - if needed
  89.     if (sm.GetHasNewItems) then begin
  90.         icon := TIcon.Create;
  91.         ImageList1.GetIcon(1, icon);
  92.  
  93.         TrayIcon.cbSize := SizeOf(TrayIcon);
  94.         TrayIcon.Wnd := Self.Handle;
  95.         TrayIcon.uID := 0;
  96.         TrayIcon.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE;
  97.         TrayIcon.uCallbackMessage := MY_WM_TRAYICON;
  98.         TrayIcon.hIcon := Icon.Handle;
  99.         TrayIcon.szTip := 'StartRight - New Items found';
  100.         ShellAPI.Shell_notifyIcon(NIM_ADD, @TrayIcon);
  101.  
  102.         icon.Free;
  103.     end else begin
  104.         Application.Terminate;
  105.     end;
  106. end;
  107.  
  108. procedure TFrmDummyRunner.WMTrayIcon(var Msg: TMessage);
  109. begin
  110.     //
  111.     // show the edit form and hilight the new items
  112.     //
  113.     if (Msg.lparam = WM_LBUTTONDBLCLK) or
  114.         (Msg.lparam = WM_LBUTTONDBLCLK) then begin
  115.         ShellAPI.Shell_notifyIcon(NIM_DELETE, @TrayIcon);
  116.  
  117.         FrmEdit.SetEndProgramOnClose(true);
  118.         FrmEdit.ShowNewItems;
  119.     end;
  120.  
  121. end;
  122.  
  123.  
  124.  
  125. procedure TfrmDummyRunner.FormDestroy(Sender: TObject);
  126. begin
  127.     sm.Free;
  128.     sr.Free;
  129. end;
  130.  
  131. procedure TfrmDummyRunner.FormCreate(Sender: TObject);
  132. begin
  133.     if (ParamCount <> 0) then self.DoYourThing;
  134. end;
  135.  
  136. end.
  137.