HMG Message functions

As noticed in Hello Word – 3 sample, HMG has a lot of message functions with name prefixed by “Msg”:

MsgBox() :

Shows a Message Box

Syntax: MsgBox(<cMessage>,[<cTitle>]) –> Nil

Example : MsgBox( “This a simple message”, “MsgBox Example” )

MsgExclamation() :

Shows a message box with an exclamation icon and a special sound.

Syntax: MsgExclamation(<cMessage>,[<cTitle>]) –> Nil

Example : MsgExclamation( “Wrong selection !”, “MsgExclamation Example” )

MsgInfo() :

Shows a message box with an information icon and a special sound.

Syntax: MsgInfo (<cMessage>,[<cTitle>]) –> Nil

Example : MsgInfo( “For your information”, “MsgInfo Example” )

MsgStop() :

Shows a message box with an stop icon and a special sound.

Syntax: MsgStop(<cMessage>,[<cTitle>]) –> Nil

Example : MsgStop( “End of file reached”, “MsgStop Example” )

MsgOkCancel() :

Shows a message box with [Ok] and [Cancel] buttons

Syntax: MsgOkCancel(<cMessage>,[<cTitle>]) –> lResponse

Example : MsgOkCancel( “Are your to exit ?”, “MsgOkCancel Example” )

MsgRetryCancel() :

Shows a message box with [Retry] and [Cancel] buttons

Syntax: MsgRetryCancel(<cMessage>,[<cTitle>]) –> lResponse

Example: MsgRetryCancel( “File open error !”, “MsgRetryCancel Example” )

MsgYesNo() :

Shows a message box with [Yes] and [No] buttons

Syntax: MsgYesNo( <cMessage> , <cTitle> ) –> lResponse

Example: MsgYesNo( “Are you sure to delete file ?”, “Confirm Delete” )

Like MsgBox(), all message functions accept parameters 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.

As noticed in syntax, the first four message functions returns NIL, and the last three returns a logical value.

<lResponse> is .T. when selected first option; Ok, Retry and Yes.

Try and observe results.

Hints :

– As a rule, every HMG project must have one and only one “Main” window. This message functions are exception of this rule. If you have only message function(s) you can build a program without main window.

– For multiple lines message body you may use CRLF. CRLF is a predefined constant in HMG. If required you may define it:

CRLF := HB_OsNewLine()

Example :

MsgBox( "This is a" + CRLF + "multiple line" + CRLF + ;
        "message", CRLF + "Multi-Line" )

– Since message function accept only “C” ( Character ) type arguments as <cMessage> and <cTitle>; for messaging other that ‘C’ type arguments, you may use appropriate function to convert  to character type. See below for an example.

Example :

 HMG Message functions
#include <>

dToday := DATE()
lMaried := .T.
nSalary := 123.456


  dToday := DATE()
  lMaried := .T.
  nSalary := 123.456
  DEFINE WINDOW frmMsgFuncs ;
     AT 0,0 ;
     WIDTH 400 ;
     HEIGHT 200 ;
     TITLE 'Message Functions' ;

        DEFINE POPUP '&Test'

          ITEM 'Msg&Box' ACTION ;
                MsgBox( "This a simple message", "MsgBox Example" ) 
          ITEM 'Msg&Exclamation' ACTION ;
                MsgExclamation( "Wrong selection !", "MsgExclamation Example" ) 
          ITEM 'Msg&Info' ACTION ;
                MsgInfo( "For your information", "MsgInfo Example" )
          ITEM 'Msg&Stop' ACTION ;
                MsgStop( "End of file reached", "MsgStop Example" ) 
          ITEM 'Msg&OkCancel' ACTION ;
                MsgOkCancel( "Are your to exit ?", "MsgOkCancel Example" ) 
          ITEM 'Msg&RetryCancel' ACTION ;
                MsgRetryCancel( "File open error !", "MsgRetryCancel Example" )
          ITEM 'Msg&YesNo' ACTION ;
                MsgYesNo( "Are you sure to delete file ?", "Confirm Delete" )
 ITEM 'Multiple &Line' ACTION ; 
       MsgBox( "This is a" + CRLF + "multiple line" + CRLF + ;
               "message", CRLF + "Multi-Line" ) 
 ITEM 'Non-Character' ACTION ; 
       MsgBox( "Today : "   + DTOC( dToday ) + CRLF +;
               "Married : " + IF( lMaried, "Yes", "No" ) + CRLF +;
               "Salary : "   + LTRIM( STR( nSalary ) ) ,;
               "Non-Char" )

 ITEM "E&xit" ACTION ThisWindow.Release


END MENU // Main()




RETURN // Main()

Hello World – 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 !" )

In HMG, there are a lot of message functions, with name prefixed by “Msg“; for details please look at HMG Message Functions page.

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

#include <>
   MsgBox( "Hello World !" )

RETURN // Main()

In fact, as a rule, every HMG project must have one and only one “Main” window. This message functions are exception of this rule. If you have only message function(s) you can build a program without main window.

Hello World – 2

In the our first example in first Quick Start page, 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 <>
      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



RETURN // Main()

DEFINE LABEL and END LABEL statements are for “Label” definition structure for the a window ( in this example Windows named as “frmHWLabel ” ). 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 :

@ 75, 125 LABEL lblHello ;
          VALUE "Hello World !" ;
          FONT "Lucida" ; 
          SIZE 16

A last note for this example : place


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


Quick Start to HMG

Building a HMG project in a few steps:

Please refer to the HMG-IDE page when needed.

Step 1 :

Download latest release of HMG package and  run HMG setup wizard. You can change default location and name of HMG; and your HMG directory structure will be like this:

Note : This structure is for HMG 3.0.39; later may change.

Attention to the HARBOUR and MINGW folders. This means that you haven’t download or install neither Harbour nor MinGW. HMG setup wizard include its for your convenience.

Attention also IDE directory.  HMG-IDE also included into package; you haven’t any more download process for it.

Step 2:


Step 3:

Select  File\New Project from menu or simply click New Project button.

Select ( make one new if necessary ) a folder and give a name your first project, say “HelloWord”. You  may use long file name; but beware including spaces and special character in your full file name.

You will see your project name ( with .hbp extension) in title of Project Browser window.

Whenever you start a new project, IDE builds a “Main.prg” and a “Main.fmg” for you and open automatically:

#include <>

Function Main

Load Window Main




You may continue working with these two main files. For following a sample/tutor it’s not mandatory using file (project, module, form ) names exactly. F.e. you can apply “HelloWord” sample by using “Main.prg” instead of “HelloWord.prg”.

If your project does not include a form ( .fmg file ) simply exclude default main form (“main.fmg” ) by using “Project\ Delete File” menu command. In this case you have delete Load, Center and Activate form command lines in the “Main.Prg”.

Caution : Use carefully “Delete File”; it’s not only “Exclude from project”, also delete selected file from disk.

If you prefer using module/file name in the sample or your own, you may exclude (delete) main module ( “Main.prg” ) too.

Step 4:

If  you prefer construct  your own module, select Project\New Module from menu or simply click “New Module” button.

Give a name for your first module ( .prg ) file; say again “HelloWord”. You can easliy see that IDE  give .prg extension your module file name and if it is first module of your project, will set and marks it as “(Main)”. Afterwards you can easliy change your main module by selecting any of your  modules and then selecting “Project\Set Module As Main” from menu. Every project must have one and only one main module.

Step 5:

Double click on your module name in the project browser. This will open your module file for editing. HMG has a default source code editor defined. You can change default module editor in “Preference” page by selecting “Tools\Preferences” from menu.

Whenever you open a new module file you will see this line on the top of page:

#include <>

This line is standard first line of all HMG modules. Unless you want build a project for console mode only, this line is necessary.

Step 6:

After this first, enter below lines to your program :

Function Main

AT 0,0 ;
WIDTH 400 ;
HEIGHT 200 ;
TITLE ‘Hello World!’ ;




Step 7:

Save your program file and then build and run your project by selecting “Project\Run” from menu or simply click “run” button.

That is all !

Analysis of program :

Function Main statement : Every HMG project must have one and only one “main” function ( or procedure ) and its name must be “main”.

DEFINE WINDOW command: Define  the main window for the program.

Win_1: Is the name of the window.

AT 0,0: Indicates the window position (row=0,column=0)

WIDTH 400: Means that the window will have 400 pixels width.

HEIGHT 200: Means that the window will have 200 pixels height.

TITLE ‘Hello World!‘: Indicates the text in the window title bar.

MAIN: Indicates that we are defining the main application window (a main window is required for all Harbour MiniGUI applications)

ACTIVATE WINDOW Win_1: Will show the window and start the event loop.

Return statement : Indicate the end of function “main”.