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