Page 1 of 1

Mouse over gadget

Posted: Wed Feb 28, 2007 11:07 pm
by oridan
Problem with mouse over gadget inside or above gadget.

Code: Select all

Procedure Window()
  If OpenWindow(0, 297, 299, 340, 160, "Mouse",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    If CreateGadgetList(WindowID(0))
      ScrollAreaGadget(1, 20, 20, 170, 120, 340, 240, 10)    
      ButtonGadget(2, 20, 25, 100, 25, "Button 1")
      TextGadget(3, 20, 70, 100, 15, "Text gadget 1")
      CloseGadgetList() 
      ButtonGadget(4, 210, 50, 100, 25, "Button 2")     
      TextGadget(5, 210, 90, 100, 15, "Text gadget 2")
    EndIf
  EndIf
EndProcedure
Window()
hCurHand = LoadCursor_(0,#IDC_HAND)
hCurArrow = LoadCursor_(0,#IDC_ARROW)
Repeat  
  Event = WaitWindowEvent()  
  WindowID = EventWindow()  
  GadgetID = EventGadget()  
  EventType = EventType()  
  Select Event
    Case #WM_MOUSEMOVE
      Select GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0),WindowMouseX(0),WindowMouseY(0))) 
        ;Case 1
          ;SetCursor_(hCurHand)
        Case 2
          SetCursor_(hCurHand); Not work          
        Case 3
          SetCursor_(hCurHand); Not work
        Case 4
          SetCursor_(hCurHand); Work        
        Case 5
          SetCursor_(hCurHand); Work 
      EndSelect
  EndSelect
  If Event = #PB_Event_Gadget          
    If GadgetID = 2
    EndIf  
    If GadgetID = 3     
    EndIf    
  EndIf  
Until Event = #PB_Event_CloseWindow
End
Help me... :cry:

Posted: Wed Feb 28, 2007 11:29 pm
by netmaestro
Couple tweaks and it all works:

Code: Select all

Procedure Window() 
  If OpenWindow(0, 297, 299, 340, 160, "Mouse",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered ) 
    If CreateGadgetList(WindowID(0)) 
      ScrollAreaGadget(1, 20, 20, 170, 120, 340, 240, 10)    
      ButtonGadget(2, 20, 25, 100, 25, "Button 1") 
      TextGadget(3, 20, 70, 100, 15, "Text gadget 1") 
      CloseGadgetList() 
      ButtonGadget(4, 210, 50, 100, 25, "Button 2")      
      TextGadget(5, 210, 90, 100, 15, "Text gadget 2") 
    EndIf 
  EndIf 
EndProcedure 
Window() 

hCurHand = LoadCursor_(0,#IDC_HAND) 
hCurArrow = LoadCursor_(0,#IDC_ARROW) 
Repeat  
  Event = WaitWindowEvent()  
  WindowID = EventWindow()  
  GadgetID = EventGadget()  
  EventType = EventType()  
  Select Event 
    Case #WM_MOUSEMOVE 
      GetCursorPos_(@cp.POINT)
      GetWindowRect_(GadgetID(1), @sa.RECT)
      If PtInRect_(sa, cp\x,cp\y)
        MapWindowPoints_(0,GetWindow_(GadgetID(1),#GW_CHILD),@cp,1)
        parent = GetWindow_(GadgetID(1),#GW_CHILD)
      Else
        MapWindowPoints_(0, WindowID(0), @cp, 1)
        parent = WindowID(0)
      EndIf
      Select GetDlgCtrlID_(ChildWindowFromPoint_(parent,cp\x,cp\y)) 
        Case 2 
          SetCursor_(hCurHand); work          
        Case 3 
          SetCursor_(hCurHand); work 
        Case 4 
          SetCursor_(hCurHand); Work        
        Case 5 
          SetCursor_(hCurHand); Work 
      EndSelect 
  EndSelect 
  If Event = #PB_Event_Gadget          
    If GadgetID = 2 
    EndIf  
    If GadgetID = 3      
    EndIf    
  EndIf  
Until Event = #PB_Event_CloseWindow 
End 
:wink:

Posted: Wed Feb 28, 2007 11:31 pm
by srod
Ah, you just beat me!!! :) Was just about to post!

Slightly different to my approach, but with the same net result!

Posted: Wed Feb 28, 2007 11:32 pm
by oridan
Thanks netmaestro!
:D

Posted: Wed Feb 28, 2007 11:32 pm
by netmaestro
the same net result!
er... dreadful pun intended? :roll:

Posted: Wed Feb 28, 2007 11:34 pm
by srod
netmaestro wrote:
the same net result!
er... dreadful pun intended? :roll:
Whoops, no pun intended. Purely accidental. :)

Posted: Wed Feb 28, 2007 11:38 pm
by netmaestro
If the static control would respond to WindowFromPoint_ the tweak could be much simpler, but it won't. hm - wonder if there's a style bit that'll make it raise its hand in response to a WindowFromPoint_ question?

Posted: Wed Feb 28, 2007 11:44 pm
by srod
#SS_NOTIFY is the one you want.

Code: Select all

SetWindowLong_(GadgetID(3), #GWL_STYLE, GetWindowLong_(GadgetID(3), #GWL_STYLE) |#SS_NOTIFY) 
etc.

This is the method I adopted, but yours is equally as good.

Posted: Wed Feb 28, 2007 11:59 pm
by netmaestro
No, I think yours is better if that style makes the static control findable, then you don't have to do all the testing and parent-choosing. I guess my wife's evaluation is correct: I'm fast but with marginal results!

Posted: Thu Mar 01, 2007 12:03 am
by srod
:)

But then WindowfromPoint_() will ignore the scroll area unless you set the same style for the static control used for the interior of the scroll area (which is only a problem of course if Oridan wishes to detect the cursor over the scroll area).

So it's swings and roundabouts really.