Code: Select all
EnableExplicit
#Window = 0
Enumeration
#Menu1
#Menu2
EndEnumeration
Enumeration
#btn1
#btn2
EndEnumeration
Structure Point64
StructureUnion
p.POINT
q.q
EndStructureUnion
EndStructure
Global hGUI
Procedure ChangeButton()
Protected id_menu, hwndWFP, cursor.POINT64
Protected BtnRest.RECT
Static hwndWFP_Old
GetCursorPos_(cursor.POINT64)
hwndWFP = WindowFromPoint_(cursor\q)
If hGUI <> hwndWFP And hwndWFP_Old <> hwndWFP
hwndWFP_Old = hwndWFP
id_menu = GetWindowLongPtr_(hwndWFP, #GWL_USERDATA)
; id_menu = GetWindowLong_(hwndWFP,#GWL_USERDATA)
; Debug hwndWFP
Debug id_menu
If id_menu
Debug 2
; GetClientRect_(hwndWFP, @BtnRest)
; ClientToScreen_(hwndWFP, @BtnRest)
GetWindowRect_(hwndWFP, @BtnRest)
With BtnRest
DisplayPopupMenu(id_menu, WindowID(#Window), \left, \bottom)
EndWith
EndIf
EndIf
EndProcedure
hGUI = OpenWindow(#Window, 0, 0, 220, 100, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If hGUI
ButtonGadget(#btn1, 10, 10, 30, 30, "1")
ButtonGadget(#btn2, 40, 10, 30, 30, "2")
If CreatePopupMenu(#Menu1)
MenuItem(1, "Item11")
MenuItem(2, "Item12")
EndIf
If CreatePopupMenu(#Menu2)
MenuItem(1, "Item21")
MenuItem(2, "Item22")
EndIf
SetGadgetData(#btn1, #Menu1)
SetGadgetData(#btn2, #Menu2)
Repeat
Select WaitWindowEvent()
Case #WM_MOUSEMOVE
ChangeButton()
Case #PB_Event_CloseWindow
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf