H
hejiesi
Unregistered / Unconfirmed
GUEST, unregistred user!
请问怎样解决?
library MHK;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
//SysUtils,
windows,
messages,
//Classes,
MapFileUnit in 'MapFileUnit.pas';
var
hNextHookProc: HHook;
HMapFile:THandle;
CommonDataCommonData;
WM_Global_MBUTTONDOWN: UINT;
WM_Global_MBUTTONUP: UINT;
WM_Global_MOUSEMOVE: UINT;
WM_Global_MOUSEWHEEL: UINT;
{$R *.RES}
{================== Install Mouse Hook Support ==============================}
function MousePosHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
pMouse : PMOUSEHOOKSTRUCT;
begin
if iCode < 0 then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
windows.Beep(1000,200);
exit;
end;
pMouse := PMOUSEHOOKSTRUCT(lParam);
CommonData^.MousePos := pMouse.pt;
case wParam of
WM_MBUTTONDOWN : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MBUTTONDOWN, 0, 1);
end;
WM_MBUTTONUP : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MBUTTONUP, 0, 1);
end;
WM_MOUSEMOVE : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MOUSEMOVE, 0, 1);
end;
WM_MOUSEWHEEL : begin
CommonData^.Direction := HIWORD(wParam);
PostMessage(CommonData^.CallBackHandle, WM_Global_MOUSEWHEEL, 0, 1);
end;
end;
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
end;
function EnableMouseHook(hld:hwnd): BOOL; stdcall;export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
hNextHookProc := SetWindowsHookEx(WH_MOUSE, MousePosHookHandler,Hinstance, 0);
if CommonData <> nil then
begin
CommonData^.CallBackHandle := hld;
//CommonData^.CallBackProcID := ProcessID;
end;
Result :=hNextHookProc <> 0 ;
end;
function DisableMouseHook: BOOL; stdcall;export;
begin
try
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc := 0;
end;
Result := hNextHookProc = 0;
except
MessageBeep(0);
Result := False;
end;
end;
procedure DLlMain(dwReason: DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH:
begin
HMapFile:=0;
MapCommonData(CommonData,HMapFile);
end; // DLL_PROCESS_ATTACH:
DLL_PROCESS_DETACH:
begin
if CommonData<>nil then UnMapCommonData(CommonData,HMapFile);
end; // DLL_PROCESS_DETACH:
end; //calse
end;
exports
EnableMouseHook,
DisableMouseHook;
begin
hNextHookProc := 0;
WM_Global_MBUTTONDOWN := RegisterWindowMessage('WM_Global_MBUTTONDOWN');
WM_Global_MBUTTONUP := RegisterWindowMessage('WM_Global_MBUTTONUP');
WM_Global_MOUSEMOVE := RegisterWindowMessage('WM_Global_MOUSEMOVE');
WM_Global_MOUSEWHEEL := RegisterWindowMessage('WM_Global_MOUSEWHEEL');
CommonData := nil;
DLLProc := @DLLMain;
DLLMain(DLL_PROCESS_ATTACH);
end.
library MHK;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
//SysUtils,
windows,
messages,
//Classes,
MapFileUnit in 'MapFileUnit.pas';
var
hNextHookProc: HHook;
HMapFile:THandle;
CommonDataCommonData;
WM_Global_MBUTTONDOWN: UINT;
WM_Global_MBUTTONUP: UINT;
WM_Global_MOUSEMOVE: UINT;
WM_Global_MOUSEWHEEL: UINT;
{$R *.RES}
{================== Install Mouse Hook Support ==============================}
function MousePosHookHandler(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
pMouse : PMOUSEHOOKSTRUCT;
begin
if iCode < 0 then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
windows.Beep(1000,200);
exit;
end;
pMouse := PMOUSEHOOKSTRUCT(lParam);
CommonData^.MousePos := pMouse.pt;
case wParam of
WM_MBUTTONDOWN : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MBUTTONDOWN, 0, 1);
end;
WM_MBUTTONUP : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MBUTTONUP, 0, 1);
end;
WM_MOUSEMOVE : begin
PostMessage(CommonData^.CallBackHandle, WM_Global_MOUSEMOVE, 0, 1);
end;
WM_MOUSEWHEEL : begin
CommonData^.Direction := HIWORD(wParam);
PostMessage(CommonData^.CallBackHandle, WM_Global_MOUSEWHEEL, 0, 1);
end;
end;
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
end;
function EnableMouseHook(hld:hwnd): BOOL; stdcall;export;
begin
Result := False;
if hNextHookProc <> 0 then Exit;
hNextHookProc := SetWindowsHookEx(WH_MOUSE, MousePosHookHandler,Hinstance, 0);
if CommonData <> nil then
begin
CommonData^.CallBackHandle := hld;
//CommonData^.CallBackProcID := ProcessID;
end;
Result :=hNextHookProc <> 0 ;
end;
function DisableMouseHook: BOOL; stdcall;export;
begin
try
if hNextHookProc <> 0 then
begin
UnhookWindowshookEx(hNextHookProc);
hNextHookProc := 0;
end;
Result := hNextHookProc = 0;
except
MessageBeep(0);
Result := False;
end;
end;
procedure DLlMain(dwReason: DWORD);
begin
case dwReason of
DLL_PROCESS_ATTACH:
begin
HMapFile:=0;
MapCommonData(CommonData,HMapFile);
end; // DLL_PROCESS_ATTACH:
DLL_PROCESS_DETACH:
begin
if CommonData<>nil then UnMapCommonData(CommonData,HMapFile);
end; // DLL_PROCESS_DETACH:
end; //calse
end;
exports
EnableMouseHook,
DisableMouseHook;
begin
hNextHookProc := 0;
WM_Global_MBUTTONDOWN := RegisterWindowMessage('WM_Global_MBUTTONDOWN');
WM_Global_MBUTTONUP := RegisterWindowMessage('WM_Global_MBUTTONUP');
WM_Global_MOUSEMOVE := RegisterWindowMessage('WM_Global_MOUSEMOVE');
WM_Global_MOUSEWHEEL := RegisterWindowMessage('WM_Global_MOUSEWHEEL');
CommonData := nil;
DLLProc := @DLLMain;
DLLMain(DLL_PROCESS_ATTACH);
end.