1 | unit SystemApi;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Api, Os, DateUtils;
|
---|
7 |
|
---|
8 | type
|
---|
9 | { TSystemApi }
|
---|
10 |
|
---|
11 | TSystemApi = class(TApi)
|
---|
12 | private
|
---|
13 | FName: string;
|
---|
14 | FText: string;
|
---|
15 | procedure WriteLineSync;
|
---|
16 | procedure RunAppSync;
|
---|
17 | public
|
---|
18 | App: TRunningApp;
|
---|
19 | System: TSystem;
|
---|
20 | procedure WriteLine(Text: string); override;
|
---|
21 | procedure RunApp(Name: string); override;
|
---|
22 | procedure Sleep(Time: TDateTime); override;
|
---|
23 | function CreateWindow: THandle; override;
|
---|
24 | procedure SetWindowName(Handle: THandle; Name: string); override;
|
---|
25 | procedure SetWindowRect(Handle: THandle; Rect: TRect); override;
|
---|
26 | procedure SetWindowVisible(Handle: THandle; Visible: Boolean); override;
|
---|
27 | end;
|
---|
28 |
|
---|
29 |
|
---|
30 | implementation
|
---|
31 |
|
---|
32 | { TSystemApi }
|
---|
33 |
|
---|
34 | procedure TSystemApi.WriteLineSync;
|
---|
35 | begin
|
---|
36 | System.Console.Write(App.App.Name + ': ' + FText);
|
---|
37 | end;
|
---|
38 |
|
---|
39 | procedure TSystemApi.RunAppSync;
|
---|
40 | begin
|
---|
41 | System.RunApp(FName);
|
---|
42 | end;
|
---|
43 |
|
---|
44 | procedure TSystemApi.WriteLine(Text: string);
|
---|
45 | begin
|
---|
46 | FText := Text;
|
---|
47 | TThread.Synchronize(App.AppThread, WriteLineSync);
|
---|
48 | end;
|
---|
49 |
|
---|
50 | procedure TSystemApi.RunApp(Name: string);
|
---|
51 | begin
|
---|
52 | FName := Name;
|
---|
53 | TThread.Synchronize(App.AppThread, RunAppSync);
|
---|
54 | end;
|
---|
55 |
|
---|
56 | procedure TSystemApi.Sleep(Time: TDateTime);
|
---|
57 | begin
|
---|
58 | App.AppThread.Sleep(Round(Time / OneMillisecond));
|
---|
59 | end;
|
---|
60 |
|
---|
61 | function TSystemApi.CreateWindow: THandle;
|
---|
62 | var
|
---|
63 | Window: TWindow;
|
---|
64 | begin
|
---|
65 | Window := System.Windows.AddNew;
|
---|
66 | Window.Handle := System.Handles.AddNew;
|
---|
67 | Result := Window.Handle;
|
---|
68 | end;
|
---|
69 |
|
---|
70 | procedure TSystemApi.SetWindowName(Handle: THandle; Name: string);
|
---|
71 | var
|
---|
72 | Window: TWindow;
|
---|
73 | begin
|
---|
74 | Window := System.Windows.SearchByHandle(Handle);
|
---|
75 | if Assigned(Window) then begin
|
---|
76 | Window.Name := Name;
|
---|
77 | System.Redraw;
|
---|
78 | end;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TSystemApi.SetWindowRect(Handle: THandle; Rect: TRect);
|
---|
82 | var
|
---|
83 | Window: TWindow;
|
---|
84 | begin
|
---|
85 | Window := System.Windows.SearchByHandle(Handle);
|
---|
86 | if Assigned(Window) then begin
|
---|
87 | Window.Rect := Rect;
|
---|
88 | System.Redraw;
|
---|
89 | end;
|
---|
90 | end;
|
---|
91 |
|
---|
92 | procedure TSystemApi.SetWindowVisible(Handle: THandle; Visible: Boolean);
|
---|
93 | var
|
---|
94 | Window: TWindow;
|
---|
95 | begin
|
---|
96 | Window := System.Windows.SearchByHandle(Handle);
|
---|
97 | if Assigned(Window) then begin
|
---|
98 | Window.Visible := Visible;
|
---|
99 | System.Redraw;
|
---|
100 | end;
|
---|
101 | end;
|
---|
102 |
|
---|
103 | end.
|
---|
104 |
|
---|