好像是鼠标坐标有问题,每次移动窗口就不见了,应该是移动到屏幕之外了.不要用GetCursorPos
#include"windows.h"#pragmadata_seg("Share")HHOOKMouseMoveHook=NULL;POINTpoint;BOOLBOO...
#include "windows.h"
#pragma data_seg ("Share")
HHOOK MouseMoveHook=NULL;
POINT point;
BOOL BOOLSetWindowPosHook=FALSE;
HWND SetWindowPosHookhwnd;
#pragma data_seg()
#pragma comment(linker,"/SECTION:Share,RWS")
LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_MOUSEMOVE)
{
if(BOOLSetWindowPosHook==TRUE)
{
SetWindowPos(SetWindowPosHookhwnd,HWND_TOP,(int)LOWORD(lParam),(int)HIWORD(lParam),0,0,SWP_NOSIZE);
}
}
if(wParam == WM_LBUTTONDOWN)
{
SetWindowPos(SetWindowPosHookhwnd,HWND_TOP,(int)LOWORD(lParam),(int)HIWORD(lParam),0,0,SWP_NOSIZE);
BOOLSetWindowPosHook=FALSE;
}
return CallNextHookEx(MouseMoveHook,nCode,wParam,lParam);
}
_declspec(dllexport)void SetMouseMoveHook(BOOL SetPos1,HWND SetPosHwnd=NULL)
{
BOOLSetWindowPosHook=SetPos1;
if(SetPosHwnd!=NULL)
SetWindowPosHookhwnd=SetPosHwnd;
MouseMoveHook=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("TestDll"),NULL);
}
我看了一下输出值,为什么(int)LOWORD(lParam)//X坐标 为负值
(int)HIWORD(lParam)//Y坐标 也不对 展开
#pragma data_seg ("Share")
HHOOK MouseMoveHook=NULL;
POINT point;
BOOL BOOLSetWindowPosHook=FALSE;
HWND SetWindowPosHookhwnd;
#pragma data_seg()
#pragma comment(linker,"/SECTION:Share,RWS")
LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam == WM_MOUSEMOVE)
{
if(BOOLSetWindowPosHook==TRUE)
{
SetWindowPos(SetWindowPosHookhwnd,HWND_TOP,(int)LOWORD(lParam),(int)HIWORD(lParam),0,0,SWP_NOSIZE);
}
}
if(wParam == WM_LBUTTONDOWN)
{
SetWindowPos(SetWindowPosHookhwnd,HWND_TOP,(int)LOWORD(lParam),(int)HIWORD(lParam),0,0,SWP_NOSIZE);
BOOLSetWindowPosHook=FALSE;
}
return CallNextHookEx(MouseMoveHook,nCode,wParam,lParam);
}
_declspec(dllexport)void SetMouseMoveHook(BOOL SetPos1,HWND SetPosHwnd=NULL)
{
BOOLSetWindowPosHook=SetPos1;
if(SetPosHwnd!=NULL)
SetWindowPosHookhwnd=SetPosHwnd;
MouseMoveHook=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("TestDll"),NULL);
}
我看了一下输出值,为什么(int)LOWORD(lParam)//X坐标 为负值
(int)HIWORD(lParam)//Y坐标 也不对 展开
2个回答
展开全部
要写成动态链接库程序,才能控制鼠标落入别的窗口的情况。
设 UWM_MOUSEMOVE 是通过 RegisterWindowMessage 注册了的消息
监测 WM_MOUSEMOVE, WM_LBUTTONDOWN。。。。
{
。。。
if(nCode < 0) { /* pass it on */
CallNextHookEx(hook, nCode, wParam, lParam);}
if(msg->message == WM_MOUSEMOVE ||
msg->message == 。。。。)
PostMessage(hWndServer, UWM_MOUSEMOVE, 0, 0);
return CallNextHookEx(hook, nCode, wParam, lParam);
}
设 UWM_MOUSEMOVE 是通过 RegisterWindowMessage 注册了的消息
监测 WM_MOUSEMOVE, WM_LBUTTONDOWN。。。。
{
。。。
if(nCode < 0) { /* pass it on */
CallNextHookEx(hook, nCode, wParam, lParam);}
if(msg->message == WM_MOUSEMOVE ||
msg->message == 。。。。)
PostMessage(hWndServer, UWM_MOUSEMOVE, 0, 0);
return CallNextHookEx(hook, nCode, wParam, lParam);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询