With HMG 3.1.3 release, (2013/06/16), all Msgxxx funstions (MsgBox, MsgExclamation, MsgInfo, MsgOkCancel, MsgRetryCancel, MsgStop, MsgYesNo) accept all type of data ( even in title ( except array ); not only characters, even others, including arrays 😮
( MsgMulti() has been replaced 😦 )
Now, we have a new ( and higly useful ) msg function MsgDebug() with an extra feature: this function accept “elastic” count of paramaters 😮
And another very handy debug function : ListCalledFunctions()
( WhereIsIt() has been replaced 😦 )
This little sample will try demonstrate these important ( at least for me 😉 ) enhancement in HMG.
Please don’t take wrong; absolutely I’m not sad by replaced my functions; on the contrary I’m very happy. Because of first, all advance in HMG make me happy; and second these new functions are definetely better than mines. And third, system functions are always better (both in speed and safety) than UDFs.
Viva HMG, viva Dr. Soto 😀
As noticed in Hello Word – 3 sample, HMG has a lot of message functions with name prefixed by “Msg”:
Shows a Message Box
Syntax: MsgBox(<cMessage>,[<cTitle>]) –> Nil
Example : MsgBox( “This a simple message”, “MsgBox Example” )
Shows a message box with an exclamation icon and a special sound.
Syntax: MsgExclamation(<cMessage>,[<cTitle>]) –> Nil
Example : MsgExclamation( “Wrong selection !”, “MsgExclamation Example” )
Shows a message box with an information icon and a special sound.
Syntax: MsgInfo (<cMessage>,[<cTitle>]) –> Nil
Example : MsgInfo( “For your information”, “MsgInfo Example” )
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” )
Shows a message box with [Ok] and [Cancel] buttons
Syntax: MsgOkCancel(<cMessage>,[<cTitle>]) –> lResponse
Example : MsgOkCancel( “Are your to exit ?”, “MsgOkCancel Example” )
Shows a message box with [Retry] and [Cancel] buttons
Syntax: MsgRetryCancel(<cMessage>,[<cTitle>]) –> lResponse
Example: MsgRetryCancel( “File open error !”, “MsgRetryCancel Example” )
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.
– 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()
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.
/* 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() *-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._.-._-._.-._.-._.-._.-._.-._.-._.-
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:
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.
( Image, Label and Button )
We are continuing with Viva_HMG.hbp, Main.prg and Main.fmg. First, let’s enlarge our form: width: 650, height: 550; and then place an image: First click “image” button the toolbar of HMG-IDE, and then click anywhere in the form. This clicked point in the form, will be left upper corner of control; in this case : image. IDE always first places controls with its default values. Our image is 405 x 340 pixel size:
We need assign a size to image control so it can hold properly our image. We can manually set these values and assign name of image file:
Background color of our form didn’t well-matched with this image. Let’s change it to white:
In this step, if we run the program we will see like this :
The STRETCH option of IMAGE control allows assigning size values to the control other than original image sizes. In this case quality of image may decrease. We need also avoiding distortion too; that is keeping fixed aspect ratio of image.
By assigning same width / height values of form and image; we can use an image as back-ground image of form. But in this case we can’t place other control onto image: because controls must not be overlap to each other. Under certain circumstances system not obstructs this. But the beneath control can’t seen.
The LABEL control is an exception of this rule by TRANSPARENT option. If a label is transparent, the beneath control may be seen partially.
Let’s add a label to our form:
The big “A” symbol in the toolbar of IDE represent LABEL. First click this button and then top of our form:
The placeholder of LABEL is primitive situation for now. We have added a new and adjusted both to our needs:
If we built and run our project after set these values, appearance will be like this:
Since two controls (labels) have been overlapped, constructing this “shadow” effect will be a few painful. You can edit .fmg file out of HMG, via any text editor when necessary.
Labels probably are most used controls in GUI programming. This control simply displays any text onto form. For xBase programmers we can say this is GUI counterpart of @ …,… SAY command. As all other GUI controls, we use coordinate system to indicate placement of control. In addition we can set size ( width, height ), back and fore color values, font properties and others as well as we need.
Labels also have ALIGNEMENT property with LEFT, RIGHT and CENTER option. In this sample used LEFT.
In addition, LABEL control supports ACTION event too. This means you can instruct a LABEL control to do an action when user clicked it; same as BUTTON.
Last control to use in this sample is button.
Beside menus, buttons are handy controls for doing an action when user clicked. Let’s see how :
The button for BUTTON in the IDE Tool Bar is this:
As precedents, one click to this button and another one to form, under image:
And two more :
Now we can tailor these buttons to our needs:
First let’s change names and captions given by IDE:
btnOpenFile, btnEditRec and btnExit to names and Open File, Edit Record and Exit to captions, consecutively:
It’s time to assign ACTIONs to this buttons.
MsgInfo( “Open File”) to ACTION of btnOpenFile
MsgInfo( “Edit Record”) to ACTION of , btnEditRec,
ThisWindow.Release to ACTION of btnExit.
And, RUN of course …
Test ACTIONs of buttons by clicking: first two will repeat the sentences in their captions via MsgInfo() function and the last will terminate program. Yes, we are using RELEASE method to the main window for terminate running program, instead of QUIT or CANCEL commands.
That’s all for now !
Produces a message that say program execution point and backward calling sequence; for debugging purposes.
Download here ( source only ).
Hexadecimal file viewer.
This is a experimental project with first intend of point out the power of Harbour and HMG. So, HexView is considerably slow on large files, please be patient.
Download here ( source only ).