-
November 16th, 2009, 03:30 AM
#1
[RESOLVED] Prompt an MFC program for mouse events
Good day. I made an MFC program that detects Mouse events through the use of Mouse Hooks. My problem now is I'm still thinking of a way on how to prompt the MFC program when a global mouse event occurs. I'm having a hard time because the Hook Procedures are written in the DLL code. Can someone please suggest a a good approach for this? Thank you very much in advance
P.S.
If it helps, here's a snippet of my Hook Procedure in my dll
Code:
extern "C" __declspec(dllexport) LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
// Get event information
PMSLLHOOKSTRUCT p = (PMSLLHOOKSTRUCT) lParam;
if(wParam == WM_MOUSEMOVE)
{
TRACE("X: %d Y: %d\n", p->pt.x, p->pt.y);
}
else if (wParam == WM_LBUTTONDOWN)
{
TRACE("Left Click\n");
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
And this is how it is installed
Code:
// Setup Windows hooks
m_HDll = ::LoadLibrary(_T("../../HookDll/Debug/HookDll.dll"));
if (!m_HDll)
{
TRACE("DLL Not Loaded: %lu\n", GetLastError());
}
HOOKPROC hkprc = (HOOKPROC)GetProcAddress(m_HDll, "_MouseHookProc@12");
if (!hkprc)
{
TRACE("Procedure not loaded: %lu\n", GetLastError());
}
m_MouseHook = SetWindowsHookEx(WH_MOUSE_LL, hkprc, m_HDll, 0);
if (!m_MouseHook)
{
TRACE("Hook Process not successful: %lu\n", GetLastError());
}
-
November 16th, 2009, 03:44 AM
#2
Re: Prompt an MFC program for mouse events
For target OS NT or later, you can use WH_MOUSE_LL hook, which can be implemented in the same exe project, without need of additional Dll.
-
November 16th, 2009, 04:24 AM
#3
Re: Prompt an MFC program for mouse events
Thank you very much. It's working now
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
|