
ActiveWindows(ThisKey)\Menu = CreateMenu( #PB_Any, WindowID(ThisWindow)) Add a map element to hold the new gadget references. Maps take a string value as key so convert the integer ThisWindow to a string. WindowBounds(ThisWindow, 250, 250, #PB_Ignore, #PB_Ignore) ThisWindow = OpenWindow( #PB_Any, 50, 50, 300, 300, "Polygon", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar) Creates a new window and gadgets, adding it and its child gadgets to the tracking map. Define.i Event, EventWindow, EventGadget, EventType, EventMenu, EventQuit Structure POLYGONWINDOWĮndStructure - Variables This map uses the previously defined structure to hold references for all the open windows. Enumeration #MenuNew #MenuClose EndEnumeration - Structures This structure will hold references to the unique elements of a window. Compiler Directives EnableExplicit Constants CompilerIf Defined(Blue, #PB_Constant) = #False #Blue = 16711680ĬompilerEndIf - Enumerations The menu commands will be the same on all the windows. Would need to be slightly different to that presented here because of the differences in
#Purebasic openwindow example code#
Resize some of the windows – notice that they can all be resized independently ofĮach other and that the polygon resizes with the window too.įinally, note that a map isn’t the only way to achieve thisīe used to do the job too, if you prefer, although the code to implement these alternatives Use the combo box in each one to select a different shape – notice that each window Use the New Window menu item to open up two or three new polygon windows. Sets an event flag to tell the program to end. If the map size reaches zero – there are no more open windows and DestroyPolygonWindow Here the child control references are removed from the map when a window is closed. Look at the DestroyPolygonWindow procedure. References are then used to resize the gadgets. This value is then used to retrieve child control references from the map and these Notice how the value of EventWindow is passed in from the event loop into this procedure. Look at the ResizePolygonWindow procedure. On the new window the references returned by these functions are stored in the map too. We then convert this to a string value and use this as When we create the window we capture the result of the OpenWindow() function in a Look at the CreatePolygonWindow procedure. POLYGONWINDOW structure previously defined. In the Variables section note that in addition to the usual variables to receive eventĭetails, a map called ActiveWindows is created using the Structure contains four integer values and so provides a place to store referencesįor a menu bar, a label, a combo box and an image plot. In the Structures section, note that the POLYGONWINDOW These will be shared on all the windows – although In the Enumerations section, note that there are only enumerations for the There are several things to notice about this program: A menu is provided to allow the creation of new windows or the closing of the A combo box is provided to allow a selection of polygons toīe drawn. This example program provides a window upon which a regular polygon is drawn in blue on aĬircumscribing grey circle.

Increased flexibility that it can provide makes this well worth the effort. Organising this is a little more complex than the examples we’ve seen so far – but the Providing we keep track of all these references we can use this to our advantage. Generated and returned as a result of the function. When this constant is used as theĪrgument to the functions that support it, a unique reference number is automatically This is where the special #PB_Any constant comes in. Several files open at once or possibly to provide several different views of the same file. So what happens if a program needs to provide more than one copy of a window? Maybe to have This is fine in the simple programs we’ve demonstrated so far but presentsĪ problem in more complex programs – only one of each of these windows can exist at the To identify a single window and each gadget So far all of our examples have used a group of constants, an enumeration, Going to look into this a little further to find out why its so important. Or if you have experimented with the Form Designer tool, you may have noticed references to a Or for any of the gadget creation commands (for example ButtonGadget()) If you’ve looked at the help articles for the OpenWindow command UserGuide - Dynamic numbering of windows and gadgets using #PB_Any
