Simple Tutorial - 1: More "Hello Word"s

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Simple Tutorial - 1: More "Hello Word"s

Post 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 <minigui.ch>

Code: Select all

Function Main

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

    ACTIVATE WINDOW Win_1

Return

After saving your modul file, build and run project :


Image

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

CENTER WINDOW Win_1

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

    MsgExclamation()

    MsgInfo()

    MsgStop()

    MsgOkCancel()

    MsgRetryCancel()

    MsgYesNo()
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 <minigui.ch>

   Function Main
      MsgBox( "Hello World !" )
   Return
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.

Regards

esgici
Viva INTERNATIONAL HMG :D
Post Reply