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 <hmg.ch>

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

PROCEDURE Main()
  SET DATE GERM
  SET CENT ON

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

        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" )
 SEPARATOR

 ITEM "E&xit" ACTION ThisWindow.Release

END POPUP // File

END MENU // Main()

END WINDOW // Main

CENTER WINDOW frmMsgFuncs

ACTIVATE WINDOW frmMsgFuncs

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 <hmg.ch>
PROCEDURE Main
   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 <hmg.ch>
PROCEDURE Main()
   DEFINE WINDOW frmHWLabel ;
      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 frmHWLabel

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

CENTER WINDOW frmHWLabel

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

HelloWordLabel