-
Notifications
You must be signed in to change notification settings - Fork 0
/
uMain.pas
130 lines (113 loc) · 3.39 KB
/
uMain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
unit uMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.WinXCtrls, Vcl.ExtCtrls,
Vcl.ComCtrls;
type
TfrmMain = class(TForm)
swActive: TToggleSwitch;
lblURL: TLabel;
edtURL: TEdit;
tmrRefresh: TTimer;
tbBrightness: TTrackBar;
spnInterval: TUpDown;
lblInterval: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
sbStatus: TStatusBar;
procedure tmrRefreshTimer(Sender: TObject);
procedure swActiveClick(Sender: TObject);
procedure tbBrightnessChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure spnIntervalChanging(Sender: TObject; var AllowChange: Boolean);
private
FLastValue: Integer;
function GetBrightnessValue(const AUrl: string): integer;
public
{ Public-Deklarationen }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
uses
System.Win.ComObj,
IdHTTP,
WinApi.ActiveX;
procedure SetBrightness(Timeout: Integer; Brightness: Byte);
var
FSWbemLocator: OleVariant;
FWMIService: OleVariant;
FWbemObjectSet: OleVariant;
FWbemObject: OleVariant;
oEnum: IEnumVARIANT;
iValue: LongWord;
begin;
FSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator');
FWMIService := FSWbemLocator.ConnectServer('localhost', 'root\WMI', '', '');
FWbemObjectSet := FWMIService.ExecQuery('SELECT * FROM WmiMonitorBrightnessMethods Where Active=True','WQL',$00000020);
oEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant;
while oEnum.Next(1, FWbemObject, iValue) = 0 do
begin
FWbemObject.WmiSetBrightness(Timeout, Brightness);
FWbemObject := Unassigned;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
LInterval: Integer;
begin
FLastValue := -1;
LInterval := tmrRefresh.Interval div 1000;
lblInterval.Caption := LInterval.ToString + ' Sek.';
end;
function TfrmMain.GetBrightnessValue(const AUrl: string): integer;
var
HTTP: TIdHTTP;
ContentStream: TStringStream;
begin
HTTP := TIdHTTP.Create(nil);
ContentStream := TStringStream.Create;
try
HTTP.Get(AUrl, ContentStream);
if HTTP.ResponseCode = 200 then
Result := ContentStream.DataString.ToInteger
else
Result := -1;
finally
ContentStream.Free;
HTTP.Free;
end;
end;
procedure TfrmMain.spnIntervalChanging(Sender: TObject;
var AllowChange: Boolean);
begin
tmrRefresh.Interval := spnInterval.Position * 1000;
lblInterval.Caption := spnInterval.Position.ToString + ' Sek.';
end;
procedure TfrmMain.swActiveClick(Sender: TObject);
begin
tmrRefresh.Enabled := swActive.IsOn;
end;
procedure TfrmMain.tbBrightnessChange(Sender: TObject);
begin
SetBrightness(tmrRefresh.Interval, tbBrightness.Position);
FLastValue := tbBrightness.Position;
sbStatus.Panels[0].Text := Format('Helligkeit: %d %', [tbBrightness.Position]);
end;
procedure TfrmMain.tmrRefreshTimer(Sender: TObject);
var
LValue: Integer;
begin
LValue := GetBrightnessValue(edtURL.Text);
if LValue <> FLastValue then
begin
FLastValue := LValue;
SetBrightness(tmrRefresh.Interval, LValue);
tbBrightness.Position := LValue;
sbStatus.Panels[0].Text := FormatDateTime('hh:mm:ss', Now) + Format(' - Helligkeit: %d %', [LValue]);
end;
end;
end.