TUTORIAL T202 - Window's Basics

File : Examples/T202 - WindowBasics.hws

It's time to see something more about HGui windows. First of all you should know that you can set a name for each window, it is optional but giving a name to a window you can easily access it and you can track its messages and events clearly, if you don't assign a name to the window the system will assign one (ramdom) for you, but in this way you are forced to store the window object somewhere to keep track of your windows.

In this tutorial you can see how we can specify a name, a position and a size for your HGui window during the creation process.

As always we have to include the HGui library:

;::: INCLUDE THE LIBRARIES DEFINITIONS :::::::::::::::::::::::::::::::::::::::::
@INCLUDE "../../+Includes.hws"

Let's enable the debug output to see what's appening…

; Enable the debug output

Now, here is how you can create a new HGui window specifying a name, a position and a default size:

; Create the HGui window
Local myWindow =
            { title = "My First Window!",      ; Window's title
              name  = "Win0",                  ; Unique window's name
              position =                       ; Position (x, y)
                 { x = 20, y = 20 },
              size =                           ; Size (w, h)
                 { w = 400, h = 100 }

Using a specific name for your windows can let you retrieve your window's object using the utility function HGui.windowFindByName() like in the following code:

Local searchedWindow = HGui.windowFindByName("Win0")
NPrint("WINDOW OBJECT   : ", myWindow)
NPrint("SEARCHED OBJECT : ", searchedWindow)
NPrint("Do you see? Are the same object!")

And that's the reason why window names must be unique, if you try to create two windows with the same name an error will be raised.

To complete our little tutorial we have to add the endless loop that checks for events:


Now we are able to give an initial position and a size to our window, to do this we have added some fields in the arguments table and that's the way all things works in HGui.

In this tutorials we have seen the following tags:

<title>     [string]    The window's title, the text rendered in the drag bar
<name>      [string]    The window's unique name, used internally for search
<position>  [table]     A table holding the window's position with the fields:
   <x>         [number]
   <y>         [number]
<size>      [table]     A table holding the window's size with the fields:
   <w>         [number]
   <h>         [number]

Screenshot of this tutorial

hollywoodlibs/hgui/tutorials/t202.txt · Ultima modifica: 2017/09/22 19:29 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0