IntPtr hookProc(int code, IntPtr wparam, IntPtr lparam)
{
if (code < 0) return CallNextHookEx(_nextHookPtr, code, wparam, lparam); MSLLHOOKSTRUCT msllStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lparam, typeof(MSLLHOOKSTRUCT));
if (msllStruct.pt.X>=300)
{
this.Text = Cursor.Position.ToString();
SetCursorPos(300, msllStruct.pt.Y);
} return IntPtr.Zero;
} public void SetHook()
{
if (_nextHookPtr != IntPtr.Zero)
{
return;
} HookProc myhookProc = new HookProc(hookProc);
//_nextHookPtr = SetWindowsHookEx((int)HookType.MouseLL, myhookProc, IntPtr.Zero, GetCurrentThreadId());
_nextHookPtr = SetWindowsHookEx((int)HookType.MouseLL, myhookProc, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
}
这段代码是全局的鼠标HOOK,让鼠标x坐标大于300的时候,回到300。
但只有当鼠标点了左右键的时候,光标才会回到300。
该如何解决呢?请不要回复我Cursor.Clip = .......... ,我只是想了解上述代码的问题,和解决方法
解决方案 »
- webbrowser 如何跨域设置iframe里的iframe的内容?(IHTMLDocument3问题)
- C#怎么解决对同一IP访问过于频繁被强行关闭连接
- 讨论一下程序与WIN7的兼容问题
- List<int> a = new List<int>(),将a赋值后,执行List<int> b = new List<int>(),b = a。当我删除b中的元素时,a中的元素也自动被删除,如何解
- 如何增加crystal reports的标尺宽度
- 帮个忙,数字数组如何赋值?
- 关于.net做Pocket PC应用程序的问题
- 大量oreilly电子书免费下载,msn机器人提供 [email protected]
- 一段简单的ado。net连不上数据库 菜鸟求解
- MVC中EF DBContext怎么实现了依赖注入
- 怎么用在winform中将数据添加到word中?
- 在Asp.Net怎么优化频繁对数据库操作问题???
你看一下这个就明白了,http://topic.csdn.net/u/20090519/15/17473596-48dc-406d-b192-a527e60d8614.html
顺便看看能不能帮我解决这个问题。
from MSDN:
The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.A window receives this message through its WindowProc function.
if (code < 0) returnCallNextHookEx(_nextHookPtr, code, wparam, lparam);另外,全局Hook要用DLL来做,SetWindowsHookEx的第3参数给DLL的ModuleHandle。
{
MSLLHOOKSTRUCT msllStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lparam, typeof(MSLLHOOKSTRUCT));
if (msllStruct.pt.X>=300)
{
this.Text = Cursor.Position.ToString();
SetCursorPos(300, msllStruct.pt.Y);
}
return CallNextHookEx(_nextHookPtr, code, wparam, lparam);
}