Page 2 of 2

Re: Writing a DLL

Posted: Sat Feb 22, 2014 6:08 pm
by nblackburn
Awesome, thanks a lot for everyone's help.

Re: Writing a DLL

Posted: Fri Aug 10, 2018 1:38 pm
by oO0XX0Oo
@chi

Is it possible to distinguish #WM_LBUTTONDBLCLK from #WM_LBUTTONDOWN in your hook?

My problem is that a left double click generates a sequence of four messages:
#WM_LBUTTONDOWN, #WM_LBUTTONUP, #WM_LBUTTONDBLCLK and #WM_LBUTTONUP

and something like this:

Code: Select all

    Select wParam
      Case #WM_LBUTTONDBLCLK
        OutputDebugString_("Left double click detected!")

      Case #WM_MBUTTONDBLCLK
        OutputDebugString_("Middle double click detected!")

      Case #WM_XBUTTONDBLCLK
        ; We need to find out if X1 or X2 button was used!
        ; https://docs.microsoft.com/en-us/windows/desktop/inputdev/wm-xbuttondblclk
        OutputDebugString_("X double click detected!")

      ; Press and hold cases
      Case #WM_LBUTTONDOWN
        OutputDebugString_("Left DOWN click detected!")
    EndSelect
Would always trigger a "normal" left down press as well. Sure, this isn't wrong per se but in this
case a real left button down (pressed and hold) should be handled differently from a double click...

Re: Writing a DLL

Posted: Fri Aug 10, 2018 5:49 pm
by chi
oO0XX0Oo wrote:Is it possible to distinguish #WM_LBUTTONDBLCLK from #WM_LBUTTONDOWN in your hook?
Don't know if this suits your needs, but you could do something like this...

Code: Select all

Enumeration
  #NLH_DLL_CONTROL = #WM_USER + 101
EndEnumeration

Procedure TimerProc(hwnd, uMsg, idEvent, dwTime)
  KillTimer_(hwnd, idEvent)
  OutputDebugString_("Left DOWN click detected!")
EndProcedure

ProcedureDLL NLH( nCode, wParam, *lParam.MOUSEHOOKSTRUCT )
  
  If nCode < 0 : ProcedureReturn CallNextHookEx_( @NLH(), nCode, wParam, *lParam ) : EndIf
  
  Select wParam
      
    Case #WM_LBUTTONDOWN
      SetTimer_(*lParam\hwnd, 1, GetDoubleClickTime_(), @TimerProc())
      
    Case #WM_LBUTTONDBLCLK
      KillTimer_(*lParam\hwnd, 1)
      OutputDebugString_("Left double click detected!")
      
  EndSelect
  
  ProcedureReturn CallNextHookEx_( @NLH(), nCode, wParam, *lParam )
  
EndProcedure

Re: Writing a DLL

Posted: Sat Aug 11, 2018 3:56 am
by Mistrel
I'm linking this here in case you have any crashes related to making a global hook DLL with PureBasic:

viewtopic.php?f=4&t=61027

I haven't tested this recently so I don't know if it's become more stable since my original report.

Re: Writing a DLL

Posted: Sat Aug 11, 2018 9:54 am
by chi
Mistrel wrote:I'm linking this here in case you have any crashes related to making a global hook DLL with PureBasic
I've never experienced such crashes with my DLL :) (nlh is running since 2011)