CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2005
    Posts
    399

    Diff b/w MouseProc & LowLevelMouseProc

    Hi all,

    What is the diffrence between the two call back functions MouseProc and LowLevelMouseProc ?
    My understanding is that LowLevelMouseProc will monitor 'every' mouse event.But there is some restrictions in the events that MouseProc will respond to, but I don't understand what those limitations are.
    Could somebody please throw some light on this.

    Thanks

  2. #2
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: Diff b/w MouseProc & LowLevelMouseProc

    According to MSDN

    The LowLevelMouseProc hook procedure is an application-defined or library-defined callback
    function used with the SetWindowsHookEx function. The system call this function every time
    a new mouse input event is about to be posted into a thread input queue. The mouse input
    can come from the local mouse driver or from calls to the mouse_event function. If the input
    comes from a call to mouse_event, the input was "injected". However, the WH_MOUSE_LL
    hook is not injected into another process. Instead, the context switches back to the
    process that installed the hook and it is called in its original context. Then the context
    switches back to the application that generated the event.


    The HOOKPROC type defines a pointer to this callback function. LowLevelMouseProc is a
    placeholder for the application-defined or library-defined function name.


    Code:
    LRESULT CALLBACK LowLevelMouseProc(          int nCode,
        WPARAM wParam,
        LPARAM lParam
    );

    Mouse Proc

    The MouseProc hook procedure is an application-defined or library-defined callback function
    used with the SetWindowsHookEx function. The system calls this function whenever an
    application calls the GetMessage or PeekMessage function and there is a mouse message
    to be processed.

    The HOOKPROC type defines a pointer to this callback function. MouseProc is a placeholder
    for the application-defined or library-defined function name.


    Code:
    LRESULT CALLBACK MouseProc(          int nCode,
        WPARAM wParam,
        LPARAM lParam
    );

  3. #3
    Join Date
    May 2005
    Posts
    399

    Re: Diff b/w MouseProc & LowLevelMouseProc

    Quote Originally Posted by MSDN
    WM_MOUSE_LL
    The system call this function every time a new mouse input event is about to be posted into a thread input queue.The mouse input can come from the local mouse driver or from calls to the mouse_event function.
    V/s
    Quote Originally Posted by MSDN
    WM_MOUSE
    The system calls this function whenever an application calls the GetMessage or PeekMessage function and there is a mouse message to be processed.
    So what exactly makes them different? When must I call one or the other? Is WM_MOUSE_LL a kind of 'global hook' and WM_MOUSE not?

  4. #4
    Join Date
    May 2005
    Posts
    4,954

    Re: Diff b/w MouseProc & LowLevelMouseProc

    Quote Originally Posted by leojose
    So what exactly makes them different?
    ok lets start with the fact that WM_MOUSE_LL is only available in NT and higher you cant use it under windows 98.

    another difference between the two is that the WM_MOUSE_LL is low level one ( by definition ) you will get the callback for the mouse input each time a mouse input has occurred.
    when using the WM_MOUSE, the callback will be called only after an application will call ::GetMessage() or ::PeekMessage(), so it basically depend on the message pump of the window.
    further more you can see difference in the parameters you are getting in each callback for instance when using the WM_MOUSE you have the hwnd in the MOUSEHOOKSTRUCT, something you wont have in the WM_MOUSE_LL.

    Quote Originally Posted by leojose
    When must I call one or the other? Is WM_MOUSE_LL a kind of 'global hook' and WM_MOUSE not?
    now that depends on what exactly you need....and what are your requirements.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  5. #5
    Join Date
    May 2005
    Posts
    399

    Re: Diff b/w MouseProc & LowLevelMouseProc

    Quote Originally Posted by golanshahar
    when using the WM_MOUSE, the callback will be called only after an application will call ::GetMessage() or ::PeekMessage(), so it basically depend on the message pump of the window.
    further more you can see difference in the parameters you are getting in each callback for instance when using the WM_MOUSE you have the hwnd in the MOUSEHOOKSTRUCT, something you wont have in the WM_MOUSE_LL.
    So...if I want to hook the mouse events of a particular window only, I can pass its hwnd and use the WM_MOUSE. whereas WM_MOUSE_LL will hook every possible mouse event.
    Quote Originally Posted by golanshahar
    now that depends on what exactly you need....and what are your requirements.
    I would like my hook to capture every mouse event, but at the same time it should also work on all Windows OSs. So would you recommend using WM_MOUSE_LL for all OSs and WM_MOUSE for win98?

    Does WM_MOUSE work as effectively as WM_MOUSE_LL when it comes to capturing all mouse events (maybe by passing NULL as hwnd or something like that)?

  6. #6
    Join Date
    May 2005
    Posts
    4,954

    Re: Diff b/w MouseProc & LowLevelMouseProc

    Quote Originally Posted by leojose
    So...if I want to hook the mouse events of a particular window only, I can pass its hwnd and use the WM_MOUSE. whereas WM_MOUSE_LL will hook every possible mouse event.
    yes you can do it, but agian you wont have the HWND if you using the WM_MOUSE_LL, but of course you can use ::WindowFromPoint(..) api to get the hwnd in the point you getting from the WM_MOUSE_LL hook.

    Quote Originally Posted by leojose
    I would like my hook to capture every mouse event, but at the same time it should also work on all Windows OSs. So would you recommend using WM_MOUSE_LL for all OSs and WM_MOUSE for win98?
    if you need it also for WIN98 then i think it is better to use WM_MOUSE instead of WM_MOUSE_LL.

    Quote Originally Posted by leojose
    Does WM_MOUSE work as effectively as WM_MOUSE_LL when it comes to capturing all mouse events (maybe by passing NULL as hwnd or something like that)?
    well again in both hooks you will get the mouse events the main difference is when your mouse callback will be called.
    go for WM_MOUSE it will be enough for you.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

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