
The PureBasic form designer simply automates the coding of the user interface. Not exactly Flappy Birds, but I hope that it explains PureBasic's programming structure adequately. Until event = #PB_Event_CloseWindowNow, when the button is clicked, the label will contain the text that has been typed into the text box. and place it in the label (identifier = 1) get the text from the text box (identifier = 2)
#Purebasic openwindow example code
Of course, there's no code there now, so it still does nothing.

Then it checks if it is an event from the button (gadget identifier 3), and if it is, executes the code within that second If/EndIf block. If it is a gadget event, it will look for the gadget identifier with the EventGadget() function. If it's not, it continues the loop, and waits for the next event. Until event = #PB_Event_CloseWindowThe first If/EndIf block added within the event loop simply checks any events that it receives, and determines if it is a gadget event, #PB_Event_Gadget. if the button is pressed (identifier = 3) That's what we'll be doing, and we'll start with the button: Furthermore, in single-window applications, the EventWindow() function could also be omitted, as all events are logically meant for it. So, the #PB_Event_CloseWindow event could be safely processed exclusively. On the other hand, in single-window applications, closing the window indicates an intention to terminate the program. Therefore, this event is processed within each window's sub-loop, so to speak, and the relevant code would be executed accordingly which is to either simply close the window, or end the program. In multi-window applications, closing any one window will trigger the #PB_Event_CloseWindow event, but that does not necessarily mean to end the program. This simplified pseudo-flow might illustrate it better:įoreverNotice how the loop structure has changed, from Repeat-Until to Repeat-Forever. Then, we'd check which gadget it's meant for, and process it accordingly. This is done with the EventWindow() function. Accordingly, in the case of multi-window applications, we'd first have to determine which window the event is intended for. Every event carries with it the identifiers of its intended window and gadget. So, let's do that now.īefore we begin, here are a few points about how PureBasic manages the events that it receives. This is because the event loop is not processing any events yet. However, the window still does nothing besides displaying itself along with its contents. The label's caption has been set as "This is a label", and the button's caption has been set as "Click Me" but the text box has been left blank. Until event = #PB_Event_CloseWindowThe window now contains three gadgets a TextGadget(), a StringGadget(), and a ButtonGadget(), positioned accordingly, and assigned identifiers of 1, 2 and 3 respectively. #PB_Window_SizeGadget | #PB_Window_ScreenCentered The only event that is processed is the #PB_Event_CloseWindow event, which as you can see, breaks the loop, and essentially ends the program:Ĭode: Select all wFlags = #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | In the above skeleton example, the loop simply waits for events, but does not process them in any way. This process continues until the #PB_Event_CloseWindow event is received, and the program terminates. Then the loop resumes, and pauses again at the WaitWindowEvent() function to await the next event.

The WaitWindowEvent() function actually pauses program execution until it receives an event, at which time the event is passed into the loop to be processed.

It should be noted that the event loop is not running in a mad frenzy, like a normal endless loop. This is known as an event-driven paradigm, and is the architecture that PureBasic is built upon. The ultimate purpose is to listen for events that the operating system passes to the program, using the WaitWindowEvent() function, and to process those received events by executing any relevant code associated with the said event. Although the example uses a Repeat-Until loop, any type of loop could be used in its place. The second part is known as the event loop, and is the backbone of any window-based PureBasic program. In order to be referenced later, PureBasic also assigns the window an identifier of 0 - the first parameter. The first part builds the interface, and simply instantiates a 300-pixel wide by 200-pixel high window at position 100, 100 on the screen, and gives it a title of My Window. Until event = #PB_Event_CloseWindowThere are two parts to this code.
