CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2007
    Location
    Philippines
    Posts
    60

    [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());
    }

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    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.

  3. #3
    Join Date
    Sep 2007
    Location
    Philippines
    Posts
    60

    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
  •  





Click Here to Expand Forum to Full Width

Featured