Main.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:2k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit Main;
  2. interface
  3. uses
  4.   Windows, Classes, Controls, Forms, StdCtrls, CoolTrayIcon;
  5. type
  6.   TMainForm = class(TForm)
  7.     CoolTrayIcon1: TCoolTrayIcon;
  8.     CheckBox1: TCheckBox;
  9.     Label1: TLabel;
  10.     Button1: TButton;
  11.     Label2: TLabel;
  12.     Label3: TLabel;
  13.     procedure CheckBox1Click(Sender: TObject);
  14.     procedure CoolTrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
  15.       Shift: TShiftState; X, Y: Integer);
  16.     procedure CoolTrayIcon1Startup(Sender: TObject; var ShowMainForm: Boolean);
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.     function LoadSetting(Key, Item: String; DefValue: Boolean): Boolean;
  20.     procedure SaveSetting(Key, Item: String; Value: Boolean);
  21.     procedure RemoveSetting(Key: String);
  22.   end;
  23. var
  24.   MainForm: TMainForm;
  25. implementation
  26. {$R *.dfm}
  27. uses
  28.   Registry;
  29. const
  30.   StartHiddenKey = 'SoftwareCoolTrayIconStartHiddenDemo';
  31. function TMainForm.LoadSetting(Key, Item: String; DefValue: Boolean): Boolean;
  32. var
  33.   Reg: TRegIniFile;
  34. begin
  35.   Reg := TRegIniFile.Create(Key);
  36.   Result := Reg.ReadBool('', Item, DefValue);
  37.   Reg.Free;
  38. end;
  39. procedure TMainForm.SaveSetting(Key, Item: String; Value: Boolean);
  40. var
  41.   Reg: TRegIniFile;
  42. begin
  43.   Reg := TRegIniFile.Create(Key);
  44.   Reg.WriteBool('', Item, Value);
  45.   Reg.Free;
  46. end;
  47. procedure TMainForm.RemoveSetting(Key: String);
  48. var
  49.   Reg: TRegIniFile;
  50. begin
  51.   Reg := TRegIniFile.Create(Key);
  52.   Reg.EraseSection('');
  53.   Reg.Free;
  54. end;
  55. procedure TMainForm.CheckBox1Click(Sender: TObject);
  56. begin
  57.   if CheckBox1.Checked then
  58.     SaveSetting(StartHiddenKey, 'StartHidden', True)
  59.   else
  60.     RemoveSetting(StartHiddenKey);
  61. end;
  62. procedure TMainForm.CoolTrayIcon1MouseDown(Sender: TObject;
  63.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  64. begin
  65.   CoolTrayIcon1.ShowMainForm;
  66. end;
  67. procedure TMainForm.CoolTrayIcon1Startup(Sender: TObject; var ShowMainForm: Boolean);
  68. var
  69.   StartHidden: Boolean;
  70. begin
  71.   StartHidden := LoadSetting(StartHiddenKey, 'StartHidden', False);
  72.   CheckBox1.Checked := StartHidden;
  73.   ShowMainForm := not StartHidden;
  74. end;
  75. procedure TMainForm.Button1Click(Sender: TObject);
  76. begin
  77.   Close;
  78. end;
  79. end.