TUTORIAL T201 - First Window

File : Examples/T201 - FirstWindow.hws



In this second appointement we will see how to create and open your first HGui window, details will be seen in the next tutorials. In this tutorial we will also see how to retrieve the HGui version at runtime and how to enable and disable the debug output. The debug output is provided by the Debug Library a it is really useful addition because it can help you a lot to debug your code when you need to track down where bugs may crash your application.

Let's start to look at the code, as always we need to include the HGui Library into your script:

;::: INCLUDE THE LIBRARIES DEFINITIONS :::::::::::::::::::::::::::::::::::::::::
@INCLUDE "../../+Includes.hws"          ;      Path relative to this application
@INCLUDE #INC_HGUI                      ;               Include the HGui library

Now let's enable the Debug Library because we want to see in the debug window what's appening:

DBG.Console.Enable(True, True)      ; The <True> parameter means that you want
                                    ; to log the timings in milliseconds, if you
                                    ; don't need this information set it to
                                    ; <False>.
                                    ; The second argument specify if you want
                                    ; colored messages or not, very useful and nice
                                    ; if your console can handle ANSI sequences.

DBG.Console.AddChannel(HGui.WChannel)    ; This command will add the HGui
                                         ; debug output to the visible
                                         ; channels for messages regarding HGui
                                         ; windows.

It's time to open your first window but without specifing too much stuff. We will store the created window object into the myFirstWindow varaible:

Local myFirstWindow = HGui.Window:new({ title = "My First Window!" })

As you can see the window's :new() method returns a window object you can use later for many purposes (like calling other methods for example), so you need to save it samewhere, in this case it has been saved in myFirstWindow- It is not mandatory to save the window object but it's advisable, especially in complex GUIs where you could have several windows to manage.

Note that if the creation fails for some reason instead of the object the boolean value False will be returned. If you want to check if a window has been created correctly you can check if it exists using HGui.windowExists() or you can check the returned object if it is really a table (any returned object is basically a table), if it is not a table the creation failed. Something like this:

If GetType(myFirstWindow) = #TABLE
  DebugPrint("Your First Window has been created!")
Else
  DebugPrint("An error occurred creating your First Window!")
EndIf

And here is the ending part of the script:

Repeat
   WaitEvent()
Forever

You should see something like this:

Some notes about the screenshot

On each line the first 6 digits are the time expressed in milliseconds where 0 is when the program has been executed.
Proceeding to the right you have a word inside square brackets: this is the debug channel name.
On the right of the channel name there is the function or method name where the message is coming from.
As you can see messages are nicely aligned to easily understand what's goin' on.

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