GUI Programming

In an earlier chapter we built a program with one button and discussed the concept of a message handler.

Let's use that program and expand on it by adding a text control and write some text in the windows.

This is the complete program - we will examine the individual elements next.

Define and Open a Window

To start our program we need to define a container for all of our user interaction. The OpenMainWindow subroutine is where we do this.

The Window

Windows are defined using the OPWNWINDOW command.

The syntax for the OPENWINDOW command is:

OPENWINDOW(win as WINDOW,l as INT,t as INT,w as INT,h as INT,flags as UINT,parent as POINTER,title as STRING,procedure as UINT)

The syntax or the command is: Our window is defined:

OPENWINDOW Main_Win,50,50,500,400,Main_Win_Style,0,"My Window",&Win_Event_Handler

It defines a Window tagged as Main_win at starting coordinates 50,50 and is 500 pixels wide and 400 pixels in height. It is titled 'My Window' and will use Win_Event_Handler to process all events related to this window.

Controls

Controls define items within a window or dialog. They tell the OS what the item is and where it is positioned and it's attributes.

For our example the controls are the 'EXIT' button and a 'STATIC' control to hold text.

The syntax for the control command is:

CONTROL(parent, type as UINT,title as STRING,l as INT,t as INT,w as INT,h as INT,flags as INT,id as UINT)

The parameters for the command are:

Now lets look at one of our controls:
CONTROL Main_Win,@BUTTON, "Exit", 215, 300, 70, 35, 0, 1
This control defines a button 'Exit' in the 'Main_Win' at position 215,300 and is 70 pixels wide and 35 pixels in height.

The Event Handler

The event handler is the heart of any program. Here all the decisions are made on how to respond to the user. The code for our event handler is below.

Events can be keystrokes, mouse movement, button press, or any other activity that will generate a captured event. In our example the events are:

Any event you wish to catch and process would be coded here.

The Main Process

Now that we have defined a window and written our event handler we need code to make it do something. In our example that is the 'MainProcess' Subroutine. It is shown below:

First we define a couple of strings to display, write to the main window, redefine the string values and write to a box:

Define string and write to main window:

Now we redefine the strings and write to the box


This completes the disection of this example program.

 

Next Section