Results 1 to 7 of 7

Thread: MouseHookStruct

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    MouseHookStruct

    I'm creating a hook into the mouse messages for my app using SetWindowsHookEx and AddressOf, and I AM receiving the Windows messages. HOWEVER, I need to use MouseHookStruct so that I can find out which window will receive the mouse message.

    I can find the MouseHookStruct declaration, but I'm not sure how to use it. I know that the lparam that I receive in MouseProc (procedure that AddressOf points to) is a pointer to the MouseHookStruct structure (according to MS), but I don't know how to use that pointer to get to the MouseHookStruct structure.

    I'm sure this is easy for many of you, but it's not for me. :
    Wade

  2. #2
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Code:
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    
    Private Type MOUSEHOOKSTRUCT
        pt As POINTAPI
        hwnd As Long
        wHitTestCode As Long
        dwExtraInfo As Long
    End Type
    
    'FOR WINDOWS 2000 Only
    Private Type MOUSEHOOKSTRUCTEX
        pt As POINTAPI
        hwnd As Long
        wHitTestCode As Long
        dwExtraInfo As Long
        mouseData As Long
    End Type
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  3. #3
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    now post the code you already have and i'll see what I can do....
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    Thanks crispin...

    I'm trapping the Tab key and need to know the control being tabbed to, but before it gets there

    In form_load:
    hKeyHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, 0&, App.ThreadID)

    In form_unload:
    Call UnhookWindowsHookEx(hKeyHook)


    In module:
    Global hKeyHook As Long

    Public Declare Function CallNextHookEx Lib "user32" _
    (ByVal hHook As Long, _
    ByVal nCode As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    Public Declare Function UnhookWindowsHookEx Lib "user32" _
    (ByVal hHook As Long) As Long

    Public Declare Function SetWindowsHookEx Lib "user32" _
    Alias "SetWindowsHookExA" _
    (ByVal idHook As Long, _
    ByVal lpfn As Long, _
    ByVal hmod As Long, _
    ByVal dwThreadId As Long) As Long


    Public Function KeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    On Error Resume Next

    'Process keys to filter
    If wParam = vbKeyTab Then
    If lParam = 983041 Then 'some part of [Tab Down]
    here is where I need to find out which control is being tabbed to, and I have lparam
    ...........
    ...........

    KeyboardProc = 1
    Exit Function
    End If
    End If

    KeyboardProc = CallNextHookEx(hKeyHook, nCode, wParam, lParam)
    End function
    Wade

  5. #5
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    heres some code to tell you what control is next in the tab order before you get to it:
    Code:
    Private Function getNextControlName(CurrentControl As Control)
    
    Dim controlname()
    Dim tabindex()
    
    Dim x As Control
    Dim n
    n = 0
    On Error Resume Next
    For Each x In Me.Controls
        If x.TabStop Then
         If Err = 0 Then
            n = n + 1
            ReDim Preserve controlname(1 To n)
            ReDim Preserve tabindex(1 To n)
            controlname(n) = x.Name
            tabindex(n) = x.tabindex
         End If
        End If
    Next x
    
    getNextControlName = ""
    
    Dim i, j
    Dim temp
    
    'sort based on tabindex
    
     For i = n - 1 To 1 Step -1
      For j = 1 To i
       If tabindex(j + 1) < tabindex(j) Then
        temp = tabindex(j)
        tabindex(j) = tabindex(j + 1)
        tabindex(j + 1) = temp
        temp = controlname(j)
        controlname(j) = controlname(j + 1)
        controlname(j + 1) = temp
       End If
      Next j
     Next i
    
     For i = 1 To n
      If CurrentControl.Name = controlname(i) Then
       If i = n Then
         getNextControlName = controlname(1)
       Else
         getNextControlName = controlname(i + 1)
       End If
       Exit For
      End If
     Next i
    
    End Function
    
    
    Private Sub Command1_Click()
      MsgBox getNextControlName(Form1.Command1)
    End Sub
    you might want to make the array public and just run the part of the function that builds the array once in the form activate event, then you can just query the array based on the tabindex of the control you are sitting on.......

    hope this helps.....
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363
    Crispin,

    I want to get this through Mousehookstruct b/c the structure can also give info like the mouse coordinates. I'll save what you gave me though....in the process of reworking what I'm making, I managed to get around the problem, but it could definitely be useful if I can't get Mousehookstruct working in other cases where I need this.

    I appreciate the time and effort. Thanks so much.
    Wade

  7. #7
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Wade,

    I think it (MOUSEHOOKSTRUCT) works now, give this project a look and lemme know what you think....
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

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