Programming AmigaOS in BASIC

Opening a Window

The next stage is to open a Window, you can open windows on a Public Screen such as Workbench or a custom screen you created earlier. You can have as many windows as you like and place them where you like. Every Window can have basic system gadgets such as Close Window, Expand/Collapse window, Move Window to Back/Front or Resize Window and there is a room for a Windows title at the top. When a user clicks on a window or a gadget in a window, it will generate an event or message which can be processed by your program.

Opening a Window using the WINDOW command, the format is:

WINDOW id,[title-string],(x1,y1)-(x2,y2)[,type][,screen-id]

The parameters are as follows:

id = Window id (1-n)
title-string = optional name of the window to appear in the title bar.
Position and size co-ordinates = Specify the top left edge and bottom right edge co-ordinates (in pixels).
Type = Flags for windows for configuring the window. Default value is 31.
Screen-id = Optional id for a custom screen.

The values for the type option are as follows:

1 = Window size can be changed by sizing gadget.
2 = Window can be moved using the title bar.
4 = Window can be moved from front to back using Back gadget.
5 = Zoom gadget is added (AmigaOS 2.x or later)
8 = Close gadget added.
16 = Contents of window re-appear after it has been covered.
32 = Window is borderless.

Here is an example of opening a Window on the default Workbench screen:

WINDOW 1, "My Window", (20,20)-(220,170), 31
SLEEP FOR 30 ' Wait for 30 seconds
WINDOW CLOSE 1
END

Other Window Statements and functions

WINDOW(n) = Function to return information about a window (ACE Basic)
WINDOW CLOSE n = Close a window.
WINDOW ON | OFF | STOP = Enable, disable or suspend a window.
WINDOW OUTPUT n = Set a window as current window.
ON WINDOW statement = Window event trapping such as the close gadget.

Processing System Gadgets on a Window

For AmigaOS to process events such as closing the Window or selecting gadgets within the window, Basic has to detect and process those events. This can be done with event trapping using the ON <event-type> statement. For example, ON WINDOW, ON GADGET, ON MOUSE, ON MENU, ON ERROR, ON TIMER and ON BREAK.

The following example will close the Window if the Close gadget has been pressed (instead of a delay like previous examples):


ON WINDOW GOTO Quit
WINDOW 1, "My Window", (20,20)-(220,170), 31
WINDOW ON ' Enable window and event trapping WHILE -1
  SLEEP
' Wait forever or event occurs
WEND Quit: WINDOW CLOSE 1 END

If there are many types of events to select such as gadgets, mouse movements, keyboard, window changes etc, then a select statement rather than an if would be more appropiate. In fact it would be better to put such code in a seperate function to be called when needed.

Next Page