C#⼀Windows API高手进,谁能给我看一个全局鼠标钩子的示例源码?

2025-01-02 10:06:33
推荐回答(1个)
回答1:

问题: C#/Windows API高手进,谁能给我看一个全局鼠标钩子的示例源码?

回答:关键代码(完整程序见附件:VS2010 基于.net framework 2.0)

        private int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Win32Api.MouseHookStruct MyMouseHookStruct = (Win32Api.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(Win32Api.MouseHookStruct));
            if (nCode < 0)
            {
                return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
            }
            else
            {
                this.Point = new Point(MyMouseHookStruct.pt.x, MyMouseHookStruct.pt.y);
                return Win32Api.CallNextHookEx(hHook, nCode, wParam, lParam);
            }
        }

祝你成功!