Successfully upgraded to Vanilla Forums v2.6. Please report any issue you may find.

2.3-Window Fundamentals

edited August 2017 in English
Now we will see how to work with windows in more detail since the window is a fundamental HGui class. All the graphic interface elements shown in a window are part of the same window and are viewed and stored as children, to be precise all the gadgets (active and passive) that make up an interface are organized in a tree structure that has a head common to the gadgets of all windows called the Root Gadget.

Every element, including the window, can have a unique name that we can use later to retrieve information or to modify our object. However, specifying a name is not required and if we decide not to do so, the system will assign a random value. In this case the only way that we will have to refer to the object in the future is to use the object returned at creation time.

Create a new script and enter the following program:
;Include the HGui library in our application
@INCLUDE "yourpath/+Includes.hws"
Also this time we enable debugging the application to follow the flow of the program during its execution:
; We activate the debug system with the following code:
DBG.Console.Enable(True, False)
Now we create a new Window object with the following code:
;Create a new window
Local myWindow =
		{ title = "My first window",
		  name = "Win0",
		  position = { x = 20, y = 20 },
		  size = { w = 400, h = 100 }
The window creation method allows you to specify an enormous amount of parameters that allows great flexibility to the programmer. In this case we have specified, in addition to the title of the window and to its name, the position that it must occupy on the screen and its size. Both of these measurements are in pixels.

As we can see we have saved our Window object in MyWindow variable this time we have specified a name for our calling Win0 window. In this short code that follows we will see how we can use the name to retrieve the Window object associated with it:
; Let's see how to use the window name to retrieve an associated object
Local searchedWindow = HGui.WindowFindByName("Win0")
NPrint("Window Object   : ", ToString(myWindow))
NPrint("Searched Object : ", ToString(searchedWindow))
NPrint("The two objects are the same Window object!")
The HGui.WindowFindByName() function allows you to search for a Window object from its name, the function returns the object found or returns False if no window matches the specified name.

That's why the name of the object must be unique. If we tried, by mistake or intentionally, to create two objects with the same name, the creation process will fail.

Now we can create windows with a position and an initial size by specifying them as method parameters. The :new() mechanism is used for all objects that we will create, including gadgets.

Finally we enter the endless loop that allows us to detect events:
Try to experiment with this tutorial by changing the initial position of the window, its initial size, or try using constants of Hollywood location: #LEFT, #RIGHT, #TOP, #BOTTOM and #CENTER.


Sign In or Register to comment.