-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathScreenSaveInit.pas
93 lines (80 loc) · 2.82 KB
/
ScreenSaveInit.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
unit ScreenSaveInit;
{this unit does the necessary init-stuff.
1) Checking parameters
2) Filling some Variables with values
2.1) ParamHandle: The value of the handle passed on command line
2.2) ConfigParent: The handle of the screen-properties-window when the config
dialog should display modal to it
3) sets IsLibrary = True to ensure the Application-Window does not show up
Version 1.0
Author: Meik Weber
IMPORTANT: See Copyright and disclaimer in README.TXT and Project Source}
interface
uses Windows; {do not use any VCL here}
{these are some globally needed values}
const
savModeRunNormal = 1; {right-click in explorer on configure}
savModeConfigure = 2; {config-dialog from screen-properties dialog}
savModeExecute = 3; {run full screen}
savModePreview = 4; {run in preview window}
savModeSetPwd = 5; {show change password dialog}
MouseTicksToIgnore = 6;
var
SaverMode : Integer; {one of the consts above}
ParamHandle : THandle; {the Handle passed on command line as parameter}
ConfigParent: hWnd; {the parent window for config-dialog}
implementation
uses SysUtils; {this is not VCL, so it's safe to use}
procedure SetParamHandle;
begin
try
ParamHandle := StrToInt (ParamStr (2));
except
ParamHandle := 0;
end;
end;
function GetSaverMode: boolean;
var
Param1 : string;
T : TextFile;
begin
ConfigParent := 0; {no modal dialog if not called via /c}
if ParamCount = 0 then
SaverMode := savModeRunNormal
else begin
Param1 := UpperCase (ParamStr (1));
if not(Param1[1] in ['-','/']) then SaverMode:= savModeRunNormal
else begin
Delete (Param1, 1, 1); {remove the first character, usually a "/" or a "-"}
case Param1[1] of
'C': begin
SaverMode := savModeConfigure;
ConfigParent := GetForegroundWindow;
end;
'A': if (ParamCount > 1) then begin {there must be a window handle}
SaverMode := savModeSetPwd;
SetParamHandle;
end;
'P': if (ParamCount > 1) then begin {there must be a window handle}
SaverMode := savModePreview;
SetParamHandle;
end;
else begin
SaverMode := savModeExecute;
ConfigParent := GetForegroundWindow;
{I need to give back the focus the currently active window after terminating the
full screen saver}
end; {else}
end; {case}
end; {else}
end; {else}
Result:= SaverMode <> SavModeRunNormal;
end;
initialization
{get cmdline parameters and fill variables, VCL is not yet available}
{if we want to use it as a screen saver we need to disable the windows.
this only works if this unit is to initialize before the VCL, so put it
as the first unit in your project source and make sure not to use another
VCL unit here}
IsLibrary := GetSaverMode;
end.