Results 1 to 3 of 3

Thread: Mouse hook

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574

    Mouse hook

    For practice, I set up a thread-specific, local mouse hook on my Visual Basic application.

    The problem is that the hit test always a 0 for the area of the screen where the mouse is currently located. And the Window class also retrieves a null string all the time.

    Can someone point out the cause of the problem? Here's the code snippet.
    Attached Files Attached Files

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574

    Re: Mouse hook

    I am suspecting there is some byte alignment issue with the MOUSEHOOKSTRUCT. The documentation is very lean and does not mention anything like that, though.

    Thoughts?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2003
    Location
    C:\Windows\Microsoft.NET\Framework
    Posts
    574

    Re: Mouse hook

    Okay, I figured it out. The modified/corrected code is attached.

    The lParam is a pointer to the MOUSEHOOKSTRUCT and should've been passed by value to the CopyMemory API. That was the reason the data was not getting copied from the lParam parameter to the structure and hence all the values I saw were wierd.

    Secondly, the Window class name would not get displayed for two reasons. The first reason being the data in the MOUSEHOOKSTRUCT was not present as mentioned above. Second, I made a silly mistake because I'd not slept well when I wrote that sample this early morning. Look at this line, I'd sent an unformatted BSTR to GetClassName.

    Code:
        LngRetVal = GetClassName(MouseData.hwnd, StrClassName, MAX_SIZE)
        If LngRetVal > 0 Then
            StrClassName = String(MAX_SIZE, vbNullChar)
            LngPos = InStr(1, StrClassName, vbNullChar)

    should've been


    Code:
    StrClassName = String(MAX_SIZE, vbNullChar)
        LngRetVal = GetClassName(MouseData.hwnd, StrClassName, MAX_SIZE)
        If LngRetVal > 0 Then
            LngPos = InStr(1, StrClassName, vbNullChar)

    The in-out/reference string should obviously have been formatted before calling GetClassName.
    Attached Files Attached Files

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