Results 1 to 7 of 7

Thread: SetWindowsHookEx and Threading

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    SetWindowsHookEx and Threading

    Hello everyone!
    I'm working with Windows 7 and my application is having some troubles with the SetWindowsHookEx API - everything works fine but when my application is not responsive (gets into a loop) the hook automatically stops (LowLevelHookTimeOut) thats because my application haven't processed the hook messages in time (In this case, mouse movements).
    When I install the hook a method called "MouseProc" gets the hook messages (mouse movements and clicks) the problem is that this method ("MouseProc") is on the same thread of my app UI - is there is any way to make the "MouseProc" method be on a separate thread? I have attached the class.
    When the user declares this class as new the hook is automaticlly installed, here is an example:
    Code:
    Dim WithEvents MHook As MouseHook
    Private Sub Form_Load(Some Args)
    MHook = New MouseHook()
    'Mouse hook installed
    End Sub
    I thought calling the API in another thread when the class being declared as new:
    Code:
    Public Sub New()
    Dim t as New Thread(AddressOf InstallHook)
    t.Start()
    End Sub
    Private Sub InstallHook()
            ''Installs a Low Level Mouse Hook
            MouseHookDelegate = New MouseProcDelegate(AddressOf MouseProc)
            MouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookDelegate, Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
    End Sub
    But it's not really working.

    Thank you and hope a solution will be found... I tried different stuff but nothing really works yet....
    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