|
-
June 3rd, 2009, 12:01 AM
#1
Convering a C# low level mouse hook to C++
Hi,
I am trying to convert over a MSDN C# code example to C++ and am struggling.
I would like to eventually monitor the mouse and keyboard commands so I can block some. Should be fairly simple but I am very much a beginner.
I am only interested in capturing commands in my form app and the controls within it, not system wide so I should not need to use a dll.
There seems to be many problems. please help.
Many Thanks
Matt.
Code:
private: System::Void Form1_Load(Object^ sender, EventArgs^ e) {
hHook = SetWindowsHookEx(WH_MOUSE_LL, hookProceedure, GetModuleHandle(NULL), 0);
}
HHOOK hHook;
HOOKPROC hookProceedure;
private int hookProceedure(int nCode, IntPtr wParam, IntPtr lParam)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
//This is the Import for the SetWindowsHookEx function.
//Use this function to install a thread-specific hook.
public:
[DllImport("user32.dll")]
static int SetWindowsHookEx(int idHook, HOOKPROC lpfn, IntPtr hInstance, int threadId);
//This is the Import for the UnhookWindowsHookEx function.
//Call this function to uninstall the hook.
public:
[DllImport("user32.dll")]
static bool UnhookWindowsHookEx(int idHook);
//This is the Import for the CallNextHookEx function.
//Use this function to pass the hook information to the next hook procedure in chain.
public:
[DllImport("user32.dll")]
static int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
Last edited by cilu; June 3rd, 2009 at 01:22 AM.
Reason: code tags
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|