Contents | Index | < Browse | Browse >
HOW TO MAKE A Gui4Cli PROGRAM
---------------------------------
The structure of a Gui4Cli program may, in the beginning, be a little
confusing to understand since it is not like other languages.
Once you understand it though, it is very easy.
* Start with G4C
First of all, every Gui4Cli program MUST start with the letters G4C
These must be the first letters of the first line of every GUI, so
that Gui4Cli knows it is a loadable file.
* GLOBAL Commands :
Then come the GLOBAL COMMANDS (if any).
These can appear in any place in the file, but it is best to put them
at the beginning of the program, for clarity's sake.
The Global Commands specify the window size and type as well as other
general characteristics of the GUI, such as the screen it should open
on etc.
The most important of the Global Commands is "WinBig", which describes
the size of the window. If this command is not declared, no window
will open.
* GRAPHICS Events :
GRAPHICS are like normal Events (see below) but since they can not be
selected, they never "happen". They are simple drawing routines,
enabling you to tart-up your GUI withy things like colored text,
lines, boxes, circles etc..
* EVENTS :
EVENTS are what drives Gui4Cli. They usually start with an "x" e.g.
xBUTTON, xLISTVIEW, xONOPEN, xONCLOSE etc.
Events can be gadgets, menus, routines, AppItems or User actions.
For example :
xBUTTON is a Gadget
xMENU is a Menu
xONCLOSE is a user action (i.e. if the window is closed)
xROUTINE is a routine
xAPPMENU is an AppMenu Item (WB Tools menu)
All events, of whatever type are treated in the same way.
Whenever an event "happens", the commands attached to it will be
executed in the order they appear.
The Gadget and Menu type events, also specify the type and specifics
of the gadget or menu.
A button type gadget (EVENT), for example, can be declared as follows :
xBUTTON 10 20 100 15 "Click me!"
This declares a button positioned 10 pixels from the left side of
the window and 20 pixels from the top. The size of the button is
100 pixels wide and 15 pixels high, and it will bear the title
"Click me!".
Most gadgets, will have a variable where they will put their value.
* EVENT MODIFIERS :
Gadgets have standard settings - for example, the text in a text
gadget will, by default, be right justified. Many of these default
settings can be changed however, by attaching Event Modifiers to them,
such as GadText LEFT.
* EVENT COMMANDS :
Event Commands are "attached" to Events.
You can attach any number of event commands to any event, making small
sub-programs (like routines or functions in other languages), which
will be executed every time the event they are attached to "happens".
These commands do different things..
Controling Gadgets SetGad, Update, Redraw..
Control Statements if/endif, ifexists, Gosub, stop
..the ones below can also be sent as arexx commands..
DOS commands Run/Launch, SendRexx, Wait, Action..
Handling guis GuiLoad, GuiOpen, Info...
Handling variables SetVar, ParseVar, Extract, RepVar..
Listview commands LVUse, LVDel, LVAdd, LVClip...
Various commands ReqFile, EZReq, MakeScreen, BreakTask..
An event command can be ARexx capable or not. I've marked them above.
If they are, it means that they can be passed to Gui4Cli from other
programs as ARexx commands and will be executed as if they were
attached to an Event.
There is no special statement that ends an Event. Each event routine
ends when another Event is declared.
EXAMPLE PROGRAM :
For example, this is a little "Hello World" program.
We'll name it "Hello.gc"
------------------------Start of file
G4C ; You must put this at the beginning.
WINBIG 100 20 100 50 TEST ; Specify a window
xONLOAD ; To be done on loading the GUI
GuiOpen Hello.gc ; Open the GUI's window.
xBUTTON 10 12 80 15 HERE! ; Specify a button
SAY "Hello World!" ; Attach a command to it.
------------------------End of file.
When you run this program, a window will open with a button in it.
When the button is clicked on, a standard con: window will appear
(since you have not specified otherwise) and the words Hello World!
will be echoed.
If you click on the window's close gadget, the window will close but
the GUI will remain in memory, since we have not told it to quit.
If we wanted the GUI unloaded from memory as soon as the window closed,
we would add the following Event :
xONCLOSE
GuiQuit Hello.gc
Note that the commands can be in capitals or small letters.
But careful - variables are case-sensitive!
We did not use "translation" in this program, since we did not have to.
Let's make a simple program using translation. (call it Hello2.gc)
------------
G4C
WINBIG 0 0 100 50 "2nd Test"
xONLOAD ; upon loading of the gui
Var1 = "Hello World" ; declare variable Var1
GUIOPEN Hello2.gc ; and open the gui
xBUTTON 10 15 80 15 "Hit Me"
SAY "$Var1" ; print the variable
IF $Var1 = "Goodbye World.." ; see explanation..
GUIQUIT Hello2.gc
ELSE
Var1 = "Goodbye World.."
ENDIF
------------
Here, in the beginning, we put the words "Hello World" into Var1, and
open our window.
When the button is clicked on, we print the value of the variable, and
afterwards we set it to "Goodbye World..", so that the second time the
user clicks on the button, after "Goodbye World.." is printed, the
GUI will quit.
Ok.. enough talking - you can see how easy it is.
The best way to learn to write GUIs, is to look at the tutorials , so
go look at them. You can change them in any way you want and see
what happens.
You will be impressed at what can be achieved (I hope :)