Page 1 of 1

#WM_LBUTTONDOWN

Posted: Sat Apr 27, 2013 3:00 am
by uweb
Hi,

may i am not the only one who miss #WM_LBUTTONDOWN.

This is no question but its also not done and therefore not enough for Tricks 'n' Tips.

Code: Select all

Procedure HookMouse(nCode, wParam, lParam)
  Static Start.l
  If nCode < 0
    ProcedureReturn CallNextHookEx_(HookMouse, nCode, wParam, lParam)
  EndIf
   *MOUSESTRUCT.MOUSEHOOKSTRUCT = lParam
   *position.POINT=*MOUSESTRUCT\pt
   Select wParam
        Case #WM_MOUSEMOVE
            If Start
              ; Splitter aktiv => die Größe der Nachbargadgets ändern
            EndIf
         Case #WM_LBUTTONDOWN
            Start=1
            Debug *position\x ; leider nur Bildschirmkoordinaten - keine Fensterkoordinaten
            Debug *position\y
           
         Case #WM_LBUTTONUP
            Start=0
            Debug *position\x
            Debug *position\y
   EndSelect
   ProcedureReturn CallNextHookEx_(HookMouse, nCode, wParam, lParam)
EndProcedure 



OpenWindow(0, 75, 14, 664, 400, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
lpdwProcessId = GetWindowThreadProcessId_(WindowID(0), @processus)          
HookMouse=SetWindowsHookEx_(#WH_MOUSE   , @HookMouse(), 0, lpdwProcessId)   
TL = StringGadget  (#PB_Any,   0,  0,  32, 200, "TL")
TV = StringGadget  (#PB_Any,  32,  0, 300, 200, "TV")

MC = StringGadget  (#PB_Any, 332, 32, 32, 136, "MC")
BO = ButtonGadget  (#PB_Any, 332,  0, 32,  32, "--")
MCT = StringGadget  (#PB_Any, 364,  0,300, 200, "MCT")
;BU = ButtonGadget  (#PB_Any, 332,168, 32,  32, "|")

U = StringGadget(#PB_Any, 0,200, 664, 200, "unten")

Repeat
  Event = WaitWindowEvent()
  
  Select Event
      
    Case #PB_Event_Gadget
      Select EventGadget()
        Case BO : Debug "BO"
        Case U  : Debug "unten"
          
      EndSelect
  EndSelect      

Until Event = #PB_Event_CloseWindow

UnhookWindowsHookEx_(HookMouse) 
Sorry for no translation. Its late in Germany.
I hope someone can use it.

Re: #WM_LBUTTONDOWN

Posted: Sat Apr 27, 2013 5:45 am
by idle
Thanks. I was just trying to remember how to set an application mouse hook

If you want to get the relative mouse positions and gadget numbers

Though you should probably only use this as a last resort.
Also it will only respond to gadget that support the functions
otherwise you need to set a #WH_Mouse_LL which is global scoped

Code: Select all

Procedure HookMouse(nCode, wParam, lParam)
   Protected hwnd,*pt.point,*mhook.MOUSEHOOKSTRUCT
   Protected px,py,rc.rect  
   Static Start
   
   If nCode = #HC_ACTION 
    *mhook = lParam
    *pt =*mhook\pt
    hwnd = *mhook\hwnd 
    GetWindowRect_(hwnd,@rc) 
    gadget = GetProp_(hwnd,"gadget")
      
    Select wParam
        Case #WM_MOUSEMOVE
            If Start
              If gadget 
                px = *pt\x - rc\Left
                py = *pt\y - rc\Top 
                Debug "mouse move gadget " + Str(gadget) + " " + Str(px) + " : " + Str(py)
              EndIf
            EndIf 
         Case #WM_LBUTTONDOWN
            If gadget 
              px = *pt\x - rc\Left
              py = *pt\y - rc\top 
              Start=1
              Debug "mouse down " + Str(gadget) + " " + Str(px) + " : " + Str(py)
            EndIf   
         Case #WM_LBUTTONUP
            If gadget 
                px = *pt\x - rc\Left
                py = *pt\y - rc\top  
                Start=0
                Debug "mouse up " + Str(gadget) + " " + Str(px) + " : " + Str(py)
            EndIf         
        EndSelect
   EndIf      
   ProcedureReturn CallNextHookEx_(HookMouse, nCode, wParam, lParam)
EndProcedure 

Define ProcessId,HookProc

OpenWindow(0, 75, 14, 664, 400, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
ProcessId = GetWindowThreadProcessId_(WindowID(0),#Null)          
HookProc=SetWindowsHookEx_(#WH_MOUSE,@HookMouse(),0,ProcessId)   
  
hwnd = StringGadget  (1,   0,  0,  32, 200, "TL")
SetProp_(hwnd,"gadget",1)

hwnd = StringGadget  (2,  32,  0, 300, 200, "TV")
SetProp_(hwnd,"gadget",2)

hwnd = StringGadget  (3, 332, 32, 32, 136, "MC")
SetProp_(hwnd,"gadget",3)

hwnd = ButtonGadget  (4, 332,  0, 32,  32, "--")
SetProp_(hwnd,"gadget",4)

hwnd = StringGadget  (5, 364,  0,300, 200, "MCT")
SetProp_(hwnd,"gadget",5)

hwnd = StringGadget(6, 0,200, 664, 200, "unten")
SetProp_(hwnd,"gadget",6)

Repeat
Event = WaitWindowEvent()
  

Until Event = #PB_Event_CloseWindow

UnhookWindowsHookEx_(HookProc)


Re: #WM_LBUTTONDOWN

Posted: Sat Apr 27, 2013 8:34 am
by uweb
Wow!
It is a sight better than my way.
Thank you verry much!