我已经做在DLL里了,但是只有鼠标自己的程序内移动的时候才会收到消息,移出自己的窗口就收不到了,何解?
请看源码版本1:
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MyMsg : ^Msg;
pPnt:TPoint;
begin
if iCode=0 then
begin
MyMsg:=Pointer(lParam);
if MyMsg.message=WM_MOUSEMOVE then
begin
GetCursorPos(pPnt);
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end;
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_GETMESSAGE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;版本2
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MouseStruct:^MOUSEHOOKSTRUCT;
x,y:integer;
begin
result:=0;
if iCode>-1 then
begin
if wParam=WM_MOUSEMOVE then
begin
MouseStruct:=pointer(lParam);
x:=MouseStruct^.pt.X;
y:=MouseStruct^.pt.Y;
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end
else
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_MOUSE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;帮忙看看,谢谢
请看源码版本1:
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MyMsg : ^Msg;
pPnt:TPoint;
begin
if iCode=0 then
begin
MyMsg:=Pointer(lParam);
if MyMsg.message=WM_MOUSEMOVE then
begin
GetCursorPos(pPnt);
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end;
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_GETMESSAGE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;版本2
function MouseProc(iCode: Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;
var
MouseStruct:^MOUSEHOOKSTRUCT;
x,y:integer;
begin
result:=0;
if iCode>-1 then
begin
if wParam=WM_MOUSEMOVE then
begin
MouseStruct:=pointer(lParam);
x:=MouseStruct^.pt.X;
y:=MouseStruct^.pt.Y;
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);
end;
end
else
result:=CallNextHookEx(iHook,iCode,wParam,lParam);
end;function SetMouseHook(h:THandle): BOOL; export;
begin
if iHook=0 then
begin
iHandle:=h;
iHook:=SetWindowsHookEx(WH_MOUSE,MouseProc,HInstance,0);
Result:=true;
end
else
begin
Result:=false;
end;
end;帮忙看看,谢谢
解决方案 »
- 判断上午和下午
- 高分赠送:vc代码如何转成Delphi代码 ?
- 请教高人,如何用程序更改本机的外网ip
- ^-^女友今天過生日^-^差點忘記了~~~^-^~~開始散分^-^生日快樂^-^ 200分(3)
- 大家来讨论下打印服务
- 好奇心:想用点不会用的东西,各位大哥们,谁知道Delphi 中的Servers 类的控件干吗用啊?一点也给分……
- delphi 注入进程的dll 如何调用另一个dll
- quickReport的问题
- 关于保存Memo中的光标位置,一小时内给分
- 谁有Delphi开发的ftp源代码
- 一个简单问题!!!!!答对者有分!!!!!!!!!!!!!!!!
- MessageDlg()函数问题:MessageDlg('aaa',information,[mbyes,mbno],0);
问题就在这里
PostMessage(iHandle,WM_APP+$100,pPnt.x,pPnt.y);具体创建你自己找书看吧, 要用到下面几个
CreateFileMapping
FlushViewOfFile
MapViewOfFile
MapViewOfFileEx
OpenFileMapping
UnmapViewOfFile
你可以参考<<Delphi 7 windodws 核心编程>>
你可以创建一个这样的全局结构
如
PShareData = ^TShareData;
TShareData =
h: HWND;
.....
end;
发送时
PostMessage(pShare^.iHandle,WM_APP+$100,pPnt.x,pPnt.y);