Code: Select all
EnableExplicit
Global event, quit
Declare OpenDialog(parent)
Runtime Enumeration
#Window
#Dialog
#Menu
#XML
#Button
EndEnumeration
Procedure OnButtonClick()
OpenDialog(#Window)
EndProcedure
Runtime Procedure OnTreeRightClick()
DisplayPopupMenu(#Menu, WindowID(DialogWindow(#Dialog)))
EndProcedure
Procedure OnMenuEvent()
MessageRequester("", "Menu item clicked")
EndProcedure
Procedure OnWindowClosed()
quit = #True
EndProcedure
Procedure OnDialogClosed()
UnbindMenuEvent(#Menu, 0, @OnMenuEvent())
FreeDialog(#Dialog)
EndProcedure
OpenWindow(#Window, 100, 100, 640, 480, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)
BindEvent(#PB_Event_CloseWindow, @OnWindowClosed(), #Window)
ButtonGadget(#Button, 10, 10, 100, 25, "Open dialog")
BindGadgetEvent(#Button, @OnButtonClick())
If CreatePopupMenu(#Menu)
MenuItem(0, "Item")
EndIf
Procedure OpenDialog(parent)
Protected xml$
xml$ + "<window id='#PB_Any' name='test' text='test' minwidth='500' minheight='400' flags='#PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget'>"
xml$ + " <tree onrightclick='OnTreeRightClick()'/>"
xml$ + "</window>"
If ParseXML(#XML, XML$) And XMLStatus(#XML) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #XML, "test", 0, 0, 0, 0, WindowID(parent))
BindEvent(#PB_Event_CloseWindow, @OnDialogClosed(), DialogWindow(#Dialog))
BindMenuEvent(#Menu, 0, @OnMenuEvent())
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
Else
Debug "XML error: " + XMLError(#XML) + " (Line: " + XMLErrorLine(#XML) + ")"
EndIf
EndProcedure
Repeat
event = WaitWindowEvent()
Until quit