Mouse over gadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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:
Last edited by netmaestro on Wed Feb 28, 2007 11:31 pm, edited 1 time in total.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Ah, you just beat me!!! :) Was just about to post!

Slightly different to my approach, but with the same net result!
I may look like a mule, but I'm not a complete ass.
oridan
Enthusiast
Enthusiast
Posts: 128
Joined: Tue Oct 12, 2004 12:14 am
Location: Italy
Contact:

Post by oridan »

Thanks netmaestro!
:D
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

the same net result!
er... dreadful pun intended? :roll:
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

netmaestro wrote:
the same net result!
er... dreadful pun intended? :roll:
Whoops, no pun intended. Purely accidental. :)
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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?
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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!
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
Post Reply