1,183
社区成员
发帖
与我相关
我的任务
分享
unit DLL;
interface
uses
Windows,Messages;
function StartHook:Boolean;stdcall;
function EndHook:Boolean;stdcall;
function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;
const
WM_MYMESSAGE=WM_USER+1024;
//type
// PShareMem=^TShareMem;
// TShareMem=record
// DATA:TMouseHookStruct;
//end;
var
hMap:THandle;
pVoid:Pointer;
hMouseHook:HHOOK;
DATA:TMouseHookStruct;
IsHooked:Boolean;
implementation
//------------------------------------------------------------------------------
function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;
begin
Result:=0;
DATA:=PMouseHookStruct(lParam)^;
if nCode < 0 then
Result:=CallNextHookEx(hMouseHook,nCode,wParam,lParam);
SendMessage(FindWindow(nil,'取词'),WM_MYMESSAGE,wParam,0);
end;
//------------------------------------------------------------------------------
function StartHook:Boolean;stdcall;
begin
if IsHooked=False then
begin
hMouseHook:=SetWindowsHookEx(WH_MOUSE,@MouseProc,HInstance,0);
if hMouseHook<> 0 then
begin
IsHooked:=True;
Result:=True;
end
else
Result:=False;
end;
end;
//------------------------------------------------------------------------------
function EndHook:Boolean;stdcall;
begin
if IsHooked=True then
begin
UnhookWindowsHookEx(hMouseHook);
IsHooked:=False;
Result:=True;
end
else
Result:=False;
end;
//------------------------------------------------------------------------------
initialization
hMap:=CreateFileMapping($FFFFFFFF,
nil,
PAGE_READWRITE,
0,
SizeOf(DATA),
PChar('mymap'));
pVoid:=MapViewOfFile(hMap,FILE_MAP_ALL_ACCESS,0,0,0);
DATA:=PMouseHookStruct(pVoid)^;
finalization
UnMapViewOfFile(pVoid); {取消映射视图}
CloseHandle(hMap); {关闭映射文件句柄}
end.
unit DLL;
interface
uses
Windows,Messages;
function StartHook:Boolean;stdcall;
function EndHook:Boolean;stdcall;
function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;
const
WM_MYMESSAGE=WM_USER+1024;
type
PShareMem=^TShareMem;
TShareMem=record
DATA:TMouseHookStruct;
end;
var
hMap:THandle;
pVoid:Pointer;
hMouseHook:HHOOK;
ShareMem:PShareMem;
IsHooked:Boolean;
implementation
//------------------------------------------------------------------------------
function MouseProc(nCode:Integer;wParam:WPARAM;lParam:LPARAM):LongInt;stdcall;
begin
Result:=0;
ShareMem^.DATA:=PMouseHookStruct(lParam)^;
if nCode < 0 then
Result:=CallNextHookEx(hMouseHook,nCode,wParam,lParam);
SendMessage(FindWindow(nil,'取词'),WM_MYMESSAGE,wParam,0);
end;
//------------------------------------------------------------------------------
function StartHook:Boolean;stdcall;
begin
if IsHooked=False then
begin
hMouseHook:=SetWindowsHookEx(WH_MOUSE,@MouseProc,HInstance,0);
if hMouseHook<> 0 then
begin
IsHooked:=True;
Result:=True;
end
else
Result:=False;
end;
end;
//------------------------------------------------------------------------------
function EndHook:Boolean;stdcall;
begin
if IsHooked=True then
begin
UnhookWindowsHookEx(hMouseHook);
IsHooked:=False;
Result:=True;
end
else
Result:=False;
end;
//------------------------------------------------------------------------------
initialization
hMap:=CreateFileMapping($FFFFFFFF,
nil,
PAGE_READWRITE,
0,
SizeOf(ShareMem),
PChar('mymap'));
pVoid:=MapViewOfFile(hMap,FILE_MAP_ALL_ACCESS,0,0,0);
ShareMem:=PShareMem(pVoid);
finalization
UnMapViewOfFile(pVoid); {取消映射视图}
CloseHandle(hMap); {关闭映射文件句柄}
end.