Page 1 of 1

MouseUp catching

Posted: Mon Feb 23, 2015 5:18 am
by Joris
Hi,

As quit many do try to catch MouseUp-events, I found this very simple solution (am I really the first one ?).
To catch MouseUp when moving the TrackBarGadget I used API's, but the code below works too.
This will most probably work for all Gadget's as well. No mouse coordinates etc. are needed.
(I hopefully wont forget it for myself :D )

Code: Select all

  Select WaitWindowEvent()
    Case #WM_LBUTTONUP 
      Select GetActiveGadget()  
        Case 1 :  
        Case 2 :  
        ...
      EndSelect

  ...
  EndSelect

Re: MouseUp catching

Posted: Mon Feb 23, 2015 7:22 am
by kvitaliy
ScrollBarGadget not working :(

Code: Select all

;{ Gadgets
Enumeration
  #Button_0
  #TrackBar_1
  #ScrollBar_2
  #ButtonImage_3
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 610, 142, 400, 400, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
      ButtonGadget(#Button_0, 65, 30, 105, 30, "Gadget_0")
      TrackBarGadget(#TrackBar_1, 30, 150, 310, 40, 0, 100, #PB_TrackBar_Ticks)
      ScrollBarGadget(#ScrollBar_2, 30, 215, 295, 25, 0, 100, 25)
      ButtonImageGadget(#ButtonImage_3, 65, 75, 100, 25, 0)
  EndIf
EndProcedure

OpenWindow_Window_0()

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  
  
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Button_0
      ElseIf EventGadget = #TrackBar_1
      ElseIf EventGadget = #ScrollBar_2
      EndIf
    Case #WM_LBUTTONUP
      Select GetActiveGadget() 
        Case #Button_0
          Debug "Button_0"
        Case #TrackBar_1
           Debug "TrackBar_1"
        Case #ScrollBar_2
          Debug "ScrollBar_2"
         Case #ButtonImage_3
          Debug "ButtonImage_3"
      EndSelect
      
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver
;
;}