Page 1 of 1

Simple Tutorial - 1: More "Hello Word"s

Posted: Fri Aug 01, 2008 12:53 am
by esgici
Simple tutorial based upon HMG Offical Tutorial for beginners.

Hello World - 2

In the our first example in Quick Start post, we wrote the "Hello World" clause on the title bar. Now, let's put it on the form.

Build a new project with "HelloWorld2" name, copy HelloWord.prg to HelloWorld2.prg and change it as below:

#include <>

Code: Select all

Function Main

        AT 0,0 ;
        WIDTH 400 ;
        HEIGHT 200 ;
        TITLE 'Hello World-2' ;
        DEFINE LABEL lblHello
           ROW 75
           COL 125
           VALUE "Hello World !"
           FONTNAME "Lucida"
           FONTSIZE 16
        END LABEL



After saving your modul file, build and run project :


DEFINE LABEL and END LABEL statements are for "Label" definiton structure for the a window ( in this example Windows named as "Win_1" ). Label itself must have a name ("lblHello" in this example), and this name must be unique, such as a variable name. Beginning these names with a descriptive prefix ( "lbl" in the example) is a good programming practice.

Between DEFINE - END statements there are main properties of this label. Row, col numbers ( in pixels of course), value (for labels, value is a string constant to write in the your form/window) and font properties (NAME and SIZE)

Almost every GUI control definitions HMG have two syntax : With DEFINE and END structure and with @ command. Thus in the above example instead of DEFINE LABEL and END LABEL structure, you can use alternate @ syntax :

Code: Select all

        @ 75, 125 LABEL lblHello ;
                  VALUE "Hello World !" ;
                  FONT "Lucida" ; 
                  SIZE 16
Don't worry, change anywhere in the example; without mistakes learning is impossible !

A last note for this example : place


statement blove END WINDOW stament and notice that how much HMG is powerful.

Hello Word - 3

Don't worry ! This is the last; and important.

Extract DEFINE LABEL - END LABEL structure or @ ...,... LABEL command ( which one is currently exist) and then instead of them place this line :

MsgBox( "Hello World !" )

There are a lot of message functions, with name prefixed by "Msg":

Code: Select all






Like MsgBox(), all message functions accept first parameter as a string constant representing the message itself. All message functions also have a second parameter, again a string constant representing the title of message box.

The first three message funcitons returns NIL, and the last three returns a logical value.

Try and observe results.

After building and running, try a more important feature: reduce your program to these minimum size:

Code: Select all

   #include <>

   Function Main
      MsgBox( "Hello World !" )
In fact, as a rule, every HMG project must have one and only one "Main" window. This message functions are exceptions of this rule. If you have only message function(s) you can build a program without main window.