How to set window close event to match each window?
Posted: Tue Oct 21, 2025 1:03 pm
I have 3 windows: exit, welcome and main.
Nothing happened until I tried put the #PB_Event_CloseWindow event for each Windows. It didn't work as expected.
How to set window close event to match each window?
That means I want to separate the #PB_Event_CloseWindow event into each window's own module. Not put it in the "main.pbi" module.
And so, the "main.pbi" module is left with just the following simple line of code:
1. declare_program.pbi
2. main.pbi (main to build/run)
3. ui_exit.pbi
4. ui_welcome.pbi
5. ui_main.pbi
Thanks for support.
Nothing happened until I tried put the #PB_Event_CloseWindow event for each Windows. It didn't work as expected.
How to set window close event to match each window?
That means I want to separate the #PB_Event_CloseWindow event into each window's own module. Not put it in the "main.pbi" module.
And so, the "main.pbi" module is left with just the following simple line of code:
Code: Select all
Repeat : WaitWindowEvent() : ForEver
Code: Select all
DeclareModule declare_program
Enumeration windows
EndEnumeration
Enumeration gadgets
EndEnumeration
Structure my_data
welcome.i
EndStructure
Global.my_data *mydata = AllocateStructure(my_data)
EndDeclareModule
Module declare_program
*mydata\welcome = #False
EndModule
DeclareModule exit_window
UseModule declare_program
Enumeration windows
#ui_exit_window
EndEnumeration
Enumeration gadgets
#exit_btn_yes
#exit_btn_no
EndEnumeration
Declare open_exit_window()
EndDeclareModule
DeclareModule welcome_window
UseModule declare_program
Enumeration windows
#ui_welcome_window
EndEnumeration
Enumeration gadgets
#welcome_btn_start
EndEnumeration
Declare open_welcome_window()
EndDeclareModule
DeclareModule main_window
UseModule declare_program
Enumeration windows
#ui_main_window
EndEnumeration
Enumeration gadgets
#main_btn_1
#main_btn_2
EndEnumeration
Declare open_main_window()
EndDeclareModule
Code: Select all
XIncludeFile "declare_program.pbi"
XIncludeFile "ui_exit.pbi"
XIncludeFile "ui_welcome.pbi"
XIncludeFile "ui_main.pbi"
UseModule declare_program
UseModule exit_window
UseModule welcome_window
UseModule main_window
If *mydata\welcome = #True
open_welcome_window()
Else
open_main_window()
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #ui_welcome_window
DisableWindow(#ui_welcome_window, #True)
open_exit_window()
Case #ui_main_window
DisableWindow(#ui_main_window, #True)
open_exit_window()
Case #ui_exit_window
If IsWindow(#ui_welcome_window)
DisableWindow(#ui_welcome_window, #False)
EndIf
If IsWindow(#ui_main_window)
DisableWindow(#ui_main_window, #False)
EndIf
CloseWindow(#ui_exit_window)
EndSelect
EndSelect
ForEver
Code: Select all
Module exit_window
UseModule welcome_window
UseModule main_window
Procedure events_exit_window()
Select Event()
Case #PB_Event_Gadget
Select EventGadget()
Case #exit_btn_no : PostEvent(#PB_Event_CloseWindow, #ui_exit_window, #PB_Ignore)
Case #exit_btn_yes : End
EndSelect
EndSelect
EndProcedure
Procedure open_exit_window()
OpenWindow(#ui_exit_window, #PB_Ignore, #PB_Ignore, 190, 100, "Exit ?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#exit_btn_no, 10, 50, 80, 45, "No")
ButtonGadget(#exit_btn_yes, 100, 50, 80, 45, "Yes")
BindEvent(#PB_Event_Menu, @events_exit_window())
BindEvent(#PB_Event_Gadget, @events_exit_window())
EndProcedure
EndModule
Code: Select all
Module welcome_window
UseModule exit_window
UseModule main_window
Procedure welcome_btn_start_handler()
HideWindow(#ui_welcome_window, #True)
open_main_window()
EndProcedure
Procedure events_welcome_window()
Select Event()
Case #PB_Event_Gadget
Select EventGadget()
Case #welcome_btn_start : CloseWindow(#ui_welcome_window) : open_main_window()
EndSelect
EndSelect
EndProcedure
Procedure open_welcome_window()
OpenWindow(#ui_welcome_window, #PB_Ignore, #PB_Ignore, 300, 400, "Welcome Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#welcome_btn_start, 10, 360, 280, 30, "Start")
BindEvent(#PB_Event_Menu, @events_welcome_window())
BindEvent(#PB_Event_Gadget, @events_welcome_window())
EndProcedure
EndModule
Code: Select all
Module main_window
UseModule exit_window
Procedure events_main_window()
Select Event()
Case #PB_Event_Gadget
Select EventGadget()
Case #main_btn_1 : Debug "#main_btn_1"
Case #main_btn_2 : Debug "#main_btn_2"
EndSelect
EndSelect
EndProcedure
Procedure open_main_window()
OpenWindow(#ui_main_window, #PB_Ignore, #PB_Ignore, 600, 400, "Main Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#main_btn_1, 10, 360, 280, 30, "Button 1")
ButtonGadget(#main_btn_2, 300, 360, 280, 30, "Button 2")
BindEvent(#PB_Event_Menu, @events_main_window())
BindEvent(#PB_Event_Gadget, @events_main_window())
EndProcedure
EndModule