source: cprs/trunk/CPRS-Chart/uInit.pas@ 1751

Last change on this file since 1751 was 1679, checked in by healthsevak, 10 years ago

Updating the working copy to CPRS version 28

File size: 5.8 KB
Line 
1unit uInit;
2
3interface
4
5uses
6 Forms, Windows, Messages, SysUtils, ExtCtrls, ORSystem;
7
8type
9{$IFDEF GroupEncounter}
10 TCPRSTimeoutTimerCondition = function: boolean;
11 TCPRSTimeoutTimerAction = procedure;
12{$ELSE}
13 TCPRSTimeoutTimerCondition = function: boolean of object;
14 TCPRSTimeoutTimerAction = procedure of object;
15{$ENDIF}
16
17procedure AutoUpdateCheck;
18
19procedure InitTimeOut(AUserCondition: TCPRSTimeoutTimerCondition;
20 AUserAction: TCPRSTimeoutTimerAction);
21procedure UpdateTimeOutInterval(NewTime: Cardinal);
22function TimedOut: boolean;
23procedure ShutDownTimeOut;
24procedure SuspendTimeout;
25procedure ResumeTimeout;
26
27implementation
28
29uses
30 fTimeout;
31
32type
33 TCPRSTimeoutTimer = class(TTimer)
34 private
35 FHooked: boolean;
36 FUserCondition: TCPRSTimeoutTimerCondition;
37 FUserAction: TCPRSTimeoutTimerAction;
38 uTimeoutInterval: Cardinal;
39 uTimeoutKeyHandle, uTimeoutMouseHandle: HHOOK;
40 protected
41 procedure ResetTimeout;
42 procedure timTimeoutTimer(Sender: TObject);
43 end;
44
45var
46 timTimeout: TCPRSTimeoutTimer = nil;
47 FTimedOut: boolean = FALSE;
48 uSuspended: boolean = False;
49
50function TimeoutKeyHook(Code: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; StdCall; forward;
51function TimeoutMouseHook(Code: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; StdCall; forward;
52
53procedure AutoUpdateCheck;
54const
55{$IFDEF GroupEncounter}
56 AppHelpFile = 'CPRSGE';
57{$ELSE}
58 AppHelpFile = 'CPRS';
59 WhatsThisHelpFile = 'CPRSWT';
60{$ENDIF}
61var
62 x, CPRSUpdate :string;
63
64begin
65 CPRSUpdate := RegReadStr(CPRS_REG_GOLD) + 'CPRSUpdate.exe';
66 if not FileExists(CPRSUpdate) then CPRSUpdate := 'CPRSUpdate.exe';
67 x := FullToPathPart(Application.ExeName) + AppHelpFile + '.HLP';
68 if AppOutOfDate(x) and FileExists(CPRSUpdate) then RunProgram(CPRSUpdate + ' XFER="' + x + '"');
69 x := FullToPathPart(Application.ExeName) + AppHelpFile + '.CNT';
70 if AppOutOfDate(x) and FileExists(CPRSUpdate) then RunProgram(CPRSUpdate + ' XFER="' + x + '"');
71 x := FullToPathPart(Application.ExeName) + WhatsThisHelpFile + '.HLP';
72 if AppOutOfDate(x) and FileExists(CPRSUpdate) then RunProgram(CPRSUpdate + ' XFER="' + x + '"');
73 x := FullToPathPart(Application.ExeName) + WhatsThisHelpFile + '.CNT';
74 if AppOutOfDate(x) and FileExists(CPRSUpdate) then RunProgram(CPRSUpdate + ' XFER="' + x + '"');
75 // Moved to CPRSUpdate.EXE in early test version of v27. This code removed for CPRS v27.27.
76 //x := FullToPathPart(Application.ExeName) + 'BORLNDMM.DLL';
77 //if AppOutOfDate(x) and FileExists(CPRSUpdate) then RunProgram(CPRSUpdate + ' XFER="' + x + '"');
78end;
79
80{** Timeout Functions **}
81
82function TimeoutKeyHook(Code: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
83{ this is called for every keyboard event that occurs while running CPRS }
84begin
85 if lParam shr 31 = 1 then timTimeout.ResetTimeout; // on KeyUp only
86 Result := CallNextHookEx(timTimeout.uTimeoutKeyHandle, Code, wParam, lParam);
87end;
88
89function TimeoutMouseHook(Code: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT;
90{ this is called for every mouse event that occurs while running CPRS }
91begin
92 if (Code >= 0) and (wParam > WM_MOUSEFIRST) and (wParam <= WM_MOUSELAST)
93 then timTimeout.ResetTimeout; // all click events
94 Result := CallNextHookEx(timTimeout.uTimeoutMouseHandle, Code, wParam, lParam);
95end;
96
97procedure InitTimeOut(AUserCondition: TCPRSTimeoutTimerCondition;
98 AUserAction: TCPRSTimeoutTimerAction);
99begin
100 if(not assigned(timTimeout)) then
101 begin
102 timTimeOut := TCPRSTimeoutTimer.Create(Application);
103 with timTimeOut do
104 begin
105 OnTimer := timTimeoutTimer;
106 FUserCondition := AUserCondition;
107 FUserAction := AUserAction;
108 uTimeoutInterval := 120000; // initially 2 minutes, will get DTIME after signon
109 uTimeoutKeyHandle := SetWindowsHookEx(WH_KEYBOARD, TimeoutKeyHook, 0, GetCurrentThreadID);
110 uTimeoutMouseHandle := SetWindowsHookEx(WH_MOUSE, TimeoutMouseHook, 0, GetCurrentThreadID);
111 FHooked := TRUE;
112 Interval := uTimeoutInterval;
113 Enabled := True;
114 end;
115 end;
116end;
117
118procedure UpdateTimeOutInterval(NewTime: Cardinal);
119begin
120 if(assigned(timTimeout)) then
121 begin
122 with timTimeout do
123 begin
124 uTimeoutInterval := NewTime;
125 Interval := uTimeoutInterval;
126 Enabled := True;
127 end;
128 end;
129end;
130
131function TimedOut: boolean;
132begin
133 Result := FTimedOut;
134end;
135
136procedure ShutDownTimeOut;
137begin
138 if(assigned(timTimeout)) then
139 begin
140 with timTimeout do
141 begin
142 Enabled := False;
143 if(FHooked) then
144 begin
145 UnhookWindowsHookEx(uTimeoutKeyHandle);
146 UnhookWindowsHookEx(uTimeoutMouseHandle);
147 FHooked := FALSE;
148 end;
149 end;
150 timTimeout.Free;
151 timTimeout := nil;
152 end;
153end;
154
155{ TCPRSTimeoutTime }
156
157procedure TCPRSTimeoutTimer.ResetTimeout;
158{ this restarts the timer whenever there is a keyboard or mouse event }
159begin
160 Enabled := False;
161 Interval := uTimeoutInterval;
162 Enabled := True;
163end;
164
165procedure TCPRSTimeoutTimer.timTimeoutTimer(Sender: TObject);
166{ when the timer expires, the application is closed after warning the user }
167begin
168 if uSuspended then
169 begin
170 ResetTimeout;
171 exit;
172 end;
173 Enabled := False;
174 if(assigned(FUserCondition)) then
175 FTimedOut := FUserCondition or AllowTimeout
176 else
177 FTimedOut := AllowTimeout;
178 if FTimedOut then
179 begin
180 if(assigned(FUserAction)) then FUserAction;
181 end
182 else
183 Enabled := True;
184end;
185
186procedure SuspendTimeout;
187begin
188 uSuspended := True;
189end;
190
191procedure ResumeTimeout;
192begin
193 if assigned(timTimeout) then
194 timTimeout.ResetTimeout;
195 uSuspended := False;
196end;
197
198initialization
199
200finalization
201 ShutDownTimeOut;
202
203end.
Note: See TracBrowser for help on using the repository browser.