Текущий архив: 2006.07.16;
Скачать: CL | DM;
Внизглобальный hook Найти похожие ветки
← →
Anubi$$$ © (2006-06-29 13:08) [0]Почему-то хук получается не глобальным?
что я не так делаю? :)
library hook;
uses
SysUtils,
Classes,
Windows,
Messages;
var MHook:HHook = 0;
MLeftBottonStatus:boolean=false;
MRightBottonStatus:boolean=false;
{$R *.res}
function HCallBack(code : integer; wParam : wParam; lParam : longint) : longint; stdcall;
begin
MLeftBottonStatus := false;
MRightBottonStatus := false;
if wParam = WM_LBUTTONDOWN then MLeftBottonStatus := true;
if wParam = WM_RBUTTONDOWN then MRightBottonStatus := true;
Result := CallNextHookEx(MHook, Code, wParam, lParam);
end;
procedure GLMHook(switch:boolean) export; stdcall;
begin
if switch then MHook := SetWindowsHookEx(WH_MOUSE, @HCallBack, hInstance, 0)
else begin UnhookWindowsHookEx(MHook); MHook := 0; end;
end;
exports GLMHook;
begin
end.
← →
Anubi$$$ © (2006-06-29 13:48) [1]второй вариант, после прочтения статьи о хуке ...
резальтат, то же :) ... :(((
library hook;
uses
SysUtils,
Classes,
Windows,
Messages;
type PGlobalDLLData = ^TGlobalDLLData;
TGlobalDLLData = packed record MHook: HWND; end;
const MMFName:PChar = "CLHookMFFName";
var GlobalData: PGlobalDLLData;
MMFHandle: THandle;
MLeftBottonStatus:boolean=false;
MRightBottonStatus:boolean=false;
{$R *.res}
function HCallBack(code : integer; wParam : Word; lParam : longint) : longint; stdcall;
begin
MLeftBottonStatus := false;
MRightBottonStatus := false;
if wParam = WM_LBUTTONDOWN then MLeftBottonStatus := true;
if wParam = WM_RBUTTONDOWN then MRightBottonStatus := true;
Result := CallNextHookEx(GlobalData^.MHook, Code, wParam, lParam);
end;
procedure GLMHook(switch:boolean) export; stdcall;
begin
if switch then GlobalData^.MHook := SetWindowsHookEx(WH_MOUSE, @HCallBack, hInstance, 0)
else begin UnhookWindowsHookEx(GlobalData^.MHook); GlobalData^.MHook := 0; end;
end;
procedure OpenGlobalData();
begin
MMFHandle := CreateFileMapping(INVALID_HANDLE_VALUE, nil, PAGE_READWRITE, 0, SizeOf(TGlobalDLLData), MMFName);
if MMFHandle <> 0 then
begin
GlobalData := MapViewOfFile(MMFHandle, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TGlobalDLLData));
if GlobalData = nil then CloseHandle(MMFHandle);
end;
end;
procedure CloseGlobalData();
begin
UnmapViewOfFile(GlobalData);
CloseHandle(MMFHandle);
end;
procedure DLLEntryPoint(dwReason: DWord); stdcall;
begin
case dwReason of
DLL_PROCESS_ATTACH: OpenGlobalData;
DLL_PROCESS_DETACH: CloseGlobalData;
end;
end;
exports GLMHook;
begin
DLLProc := @DLLEntryPoint;
DLLEntryPoint(DLL_PROCESS_ATTACH);
end.
Страницы: 1 вся ветка
Текущий архив: 2006.07.16;
Скачать: CL | DM;
Память: 0.45 MB
Время: 0.01 c