vmars316 wrote:...how do I Terminate a 'stand alone' program that I started by double-clicking an *.exe , or from compiler (F5) , other than clicking on 'Red X' button?
Hi Vern. I think some clarification is in order.
Pressing
F5 in the IDE simply executes the currently loaded PureBasic program. In that case, to terminate such a program,
other than clicking on 'Red X' button, simply implement a flag that breaks the event loop, like this:
Code: Select all
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 400, "Main Window", wFlags)
ButtonGadget(1, 250, 180, 100, 30, "E X I T")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 1
appQuit = 1
EndSelect
EndSelect
Until appQuit = 1
Alternatively, the
PostEvent() function could also be used:
Code: Select all
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, #PB_Any, #PB_Any, 600, 400, "Main Window", wFlags)
ButtonGadget(1, 250, 180, 100, 30, "E X I T")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
PostEvent(#PB_Event_CloseWindow)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
If I've understood correctly.
