Writing a DLL

Just starting out? Need help? Post your questions and find answers here.
User avatar
nblackburn
User
User
Posts: 67
Joined: Mon Aug 19, 2013 1:22 am
Location: United Kingdom
Contact:

Re: Writing a DLL

Post by nblackburn »

Awesome, thanks a lot for everyone's help.
Image
oO0XX0Oo
User
User
Posts: 78
Joined: Thu Aug 10, 2017 7:35 am

Re: Writing a DLL

Post 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...
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Writing a DLL

Post 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
Et cetera is my worst enemy
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: Writing a DLL

Post 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.
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Writing a DLL

Post 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)
Et cetera is my worst enemy
Post Reply