You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
5.5 KiB
Plaintext
202 lines
5.5 KiB
Plaintext
{
|
|
Copyright (C) 2002-2004 Massimo Melina (www.rejetto.com)
|
|
|
|
This file is part of &RQ.
|
|
|
|
&RQ is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
&RQ is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with &RQ; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
}
|
|
unit hook;
|
|
{$I RnQConfig.inc}
|
|
|
|
interface
|
|
|
|
uses
|
|
windows, sysutils, messages, classes;
|
|
|
|
{$I NoRTTI.inc}
|
|
|
|
procedure installHook(hdl: THandle);
|
|
// procedure installHook;
|
|
procedure uninstallHook;
|
|
// function isHooked:boolean; inline;
|
|
function isMoved(awTime: Integer = -1): Boolean;
|
|
|
|
var
|
|
IsHooked: Boolean;
|
|
IsLocked: Boolean = false;
|
|
|
|
function RegisterSessionNotification(Wnd: HWND; dwFlags: DWORD): Boolean;
|
|
function UnRegisterSessionNotification(Wnd: HWND): Boolean;
|
|
|
|
implementation
|
|
|
|
uses
|
|
globalLib, utilLib, RQLog;
|
|
|
|
type
|
|
TintFun = function: integer;
|
|
|
|
const
|
|
// Only session notifications involving the session attached to by the window
|
|
// identified by the hWnd parameter value are to be received.
|
|
NOTIFY_FOR_THIS_SESSION = 0;
|
|
// All session notifications are to be received.
|
|
NOTIFY_FOR_ALL_SESSIONS = 1;
|
|
|
|
var
|
|
oldHook: Boolean;
|
|
FRegisteredSessionNotification: Boolean;
|
|
SessNotifHndl: THandle;
|
|
GetLII: function(var plii: TLastInputInfo): BOOL; stdcall;
|
|
|
|
procedure installHook(hdl: THandle);
|
|
var
|
|
hndl: THandle;
|
|
begin
|
|
SessNotifHndl := hdl;
|
|
FRegisteredSessionNotification := RegisterSessionNotification(SessNotifHndl, NOTIFY_FOR_THIS_SESSION);
|
|
if Win32MajorVersion >= 5 then
|
|
begin
|
|
hndl := GetModuleHandle('user32.dll');
|
|
@GetLII := GetProcAddress(hndl, 'GetLastInputInfo');
|
|
if @GetLII = NIL then
|
|
Exit;
|
|
isHooked := TRUE;
|
|
oldHook := false;
|
|
end
|
|
end; // installHook
|
|
|
|
procedure uninstallHook;
|
|
begin
|
|
if not isHooked then
|
|
Exit;
|
|
if FRegisteredSessionNotification then
|
|
UnRegisterSessionNotification(SessNotifHndl);
|
|
SessNotifHndl := 0;
|
|
isHooked := false;
|
|
end; // uninstallHook
|
|
|
|
// function isHooked:boolean; inline;
|
|
// begin result:=hooked end;
|
|
//
|
|
|
|
function LastInput: DWORD;
|
|
var
|
|
LInput: TLastInputInfo;
|
|
begin
|
|
LInput.cbSize := SizeOf(TLastInputInfo);
|
|
GetLII(LInput);
|
|
Result := GetTickCount - LInput.dwTime;
|
|
end;
|
|
|
|
function IsMoved(awTime: Integer = -1): Boolean;
|
|
begin
|
|
Result := false;
|
|
if awTime < 0 then
|
|
awTime := autoaway.time;
|
|
if (LastInput+5 < awTime) then
|
|
Result := True;
|
|
end;
|
|
|
|
function RegisterSessionNotification(Wnd: HWND; dwFlags: DWORD): Boolean;
|
|
// The RegisterSessionNotification function registers the specified window
|
|
// to receive session change notifications.
|
|
// Parameters:
|
|
// hWnd: Handle of the window to receive session change notifications.
|
|
// dwFlags: Specifies which session notifications are to be received:
|
|
// (NOTIFY_FOR_THIS_SESSION, NOTIFY_FOR_ALL_SESSIONS)
|
|
type
|
|
TWTSRegisterSessionNotification = function(Wnd: HWND; dwFlags: DWORD): BOOL; stdcall;
|
|
var
|
|
hWTSapi32dll: THandle;
|
|
WTSRegisterSessionNotification: TWTSRegisterSessionNotification;
|
|
begin
|
|
Result := false;
|
|
hWTSapi32dll := LoadLibrary('Wtsapi32.dll');
|
|
if (hWTSapi32dll > 0) then
|
|
begin
|
|
try
|
|
@WTSRegisterSessionNotification := GetProcAddress(hWTSapi32dll, 'WTSRegisterSessionNotification');
|
|
if assigned(WTSRegisterSessionNotification) then
|
|
begin
|
|
Result := WTSRegisterSessionNotification(Wnd, dwFlags);
|
|
end;
|
|
finally
|
|
if hWTSapi32dll > 0 then
|
|
FreeLibrary(hWTSapi32dll);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function UnRegisterSessionNotification(Wnd: HWND): Boolean;
|
|
// The RegisterSessionNotification function unregisters the specified window
|
|
// Parameters:
|
|
// hWnd: Handle to the window
|
|
type
|
|
TWTSUnRegisterSessionNotification = function(Wnd: HWND): BOOL; stdcall;
|
|
var
|
|
hWTSapi32dll: THandle;
|
|
WTSUnRegisterSessionNotification: TWTSUnRegisterSessionNotification;
|
|
begin
|
|
Result := false;
|
|
hWTSapi32dll := LoadLibrary('Wtsapi32.dll');
|
|
if (hWTSapi32dll > 0) then
|
|
begin
|
|
try
|
|
@WTSUnRegisterSessionNotification := GetProcAddress(hWTSapi32dll, 'WTSUnRegisterSessionNotification');
|
|
if assigned(WTSUnRegisterSessionNotification) then
|
|
begin
|
|
Result := WTSUnRegisterSessionNotification(Wnd);
|
|
end;
|
|
finally
|
|
if hWTSapi32dll > 0 then
|
|
FreeLibrary(hWTSapi32dll);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function IsFullScreenMode(): Boolean;
|
|
var
|
|
w, h: integer;
|
|
Wnd: HWND;
|
|
rcWindow: TRECT;
|
|
begin
|
|
w := GetSystemMetrics(SM_CXSCREEN);
|
|
h := GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
// Wnd := 0;
|
|
// repeat
|
|
// Wnd := FindWindowEx(0, Wnd, NIL, NIL);
|
|
Wnd := GetForegroundWindow;
|
|
if Wnd > 0 then
|
|
if (GetWindowLongPtr(Wnd, GWL_EXSTYLE) and WS_EX_TOPMOST) > 0 then
|
|
begin
|
|
GetWindowRect(Wnd, rcWindow);
|
|
if ((w = (rcWindow.right - rcWindow.left)) and (h = (rcWindow.bottom - rcWindow.top))) then
|
|
begin
|
|
Result := TRUE;
|
|
Exit;
|
|
end;
|
|
end;
|
|
// until Wnd = 0;
|
|
Result := false;
|
|
end;
|
|
|
|
begin
|
|
isHooked := false;
|
|
SessNotifHndl := 0;
|
|
FRegisteredSessionNotification := false;
|
|
end.
|