I'll show you three different ways you can do it:
Method 1: ChildWindowFromPoint
Code: Select all
Structure wndMain
window.l
btnClose.l
btnViewParents.l
txtMessage.l
EndStructure
MainWindow.wndMain
;assign Id's
MainWindow\window=0
MainWindow\btnClose=1
MainWindow\btnViewParents=2
MainWindow\txtMessage=3
;Create window
OpenWindow(mainWindow\window,0,0,500,200,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(mainWindow\window))
ButtonGadget(MainWindow\btnClose,400,150,40,30,"CLOSE")
TextGadget(MainWindow\txtMessage,10,10,200,30,"TEST")
Repeat
event.l=WaitWindowEvent(10) ;catch all events from any window
If event = #WM_MOUSEMOVE
If ChildWindowFromPoint_(WindowID(Mainwindow\window), WindowMouseX(Mainwindow\window), WindowMouseY(Mainwindow\window)) = GadgetID(Mainwindow\btnclose)
SetGadgetText(MainWindow\txtMessage,"Mouse over button")
Else
SetGadgetText(MainWindow\txtMessage,"Where's the mouse?")
EndIf
EndIf
If event=#PB_Event_Gadget ;If event is from a gadget
Select EventGadget() ; get the gadget number
EndSelect
EndIf
Until event=#PB_Event_CloseWindow And EventWindow()=MainWindow\window
Method 2: PtinRect
Code: Select all
Structure wndMain
window.l
btnClose.l
btnViewParents.l
txtMessage.l
EndStructure
MainWindow.wndMain
;assign Id's
MainWindow\window=0
MainWindow\btnClose=1
MainWindow\btnViewParents=2
MainWindow\txtMessage=3
;Create window
OpenWindow(mainWindow\window,0,0,500,200,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(mainWindow\window))
ButtonGadget(MainWindow\btnClose,400,150,40,30,"CLOSE")
TextGadget(MainWindow\txtMessage,10,10,200,30,"TEST")
Repeat
event.l=WaitWindowEvent(10) ;catch all events from any window
If event = #WM_MOUSEMOVE
GetWindowRect_(GadgetID(Mainwindow\btnclose), @gr.RECT)
GetCursorPos_(@cp.point)
If PtInRect_(@gr, cp\x, cp\y)
SetGadgetText(MainWindow\txtMessage,"Mouse over button")
Else
SetGadgetText(MainWindow\txtMessage,"Where's the mouse?")
EndIf
EndIf
If event=#PB_Event_Gadget ;If event is from a gadget
Select EventGadget() ; get the gadget number
EndSelect
EndIf
Until event=#PB_Event_CloseWindow And EventWindow()=MainWindow\window
Method 3: PtinRegion
Code: Select all
Structure wndMain
window.l
btnClose.l
btnViewParents.l
txtMessage.l
EndStructure
MainWindow.wndMain
;assign Id's
MainWindow\window=0
MainWindow\btnClose=1
MainWindow\btnViewParents=2
MainWindow\txtMessage=3
;Create window
OpenWindow(mainWindow\window,0,0,500,200,"TEST",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(mainWindow\window))
ButtonGadget(MainWindow\btnClose,400,150,40,30,"CLOSE")
TextGadget(MainWindow\txtMessage,10,10,200,30,"TEST")
Repeat
event.l=WaitWindowEvent(10) ;catch all events from any window
If event = #WM_MOUSEMOVE
If Not hRgn : hRgn = CreateRectRgn_(0,0, 40, 30) : EndIf
GetCursorPos_(@cp.POINT)
MapWindowPoints_(#Null, GadgetID(Mainwindow\btnclose), @cp, 1)
If PtInRegion_(hRgn, cp\x, cp\y)
SetGadgetText(MainWindow\txtMessage,"Mouse over button")
Else
SetGadgetText(MainWindow\txtMessage,"Where's the mouse?")
EndIf
EndIf
If event=#PB_Event_Gadget ;If event is from a gadget
Select EventGadget() ; get the gadget number
EndSelect
EndIf
Until event=#PB_Event_CloseWindow And EventWindow()=MainWindow\window