|
'C'ing through the window
'pains'
by Steve Ollett
Introduction Back in the March 2001 issue
of MyAtari, I wrote a tutorial covering the creation
of menus in C, using Lattice C and WERCS.
In the meantime, there's
been the birth of my daughter, extensive decorating
of my house, and of course researching into window handling
using C. This month I'm back with a short tutorial on
how to interact with GEM windows and menus.
At
the end of this article you will find a link to a ZIP
archive that contains all the files you'll need to
make the most of this tutorial, including the executable
and source code.
So
what does 'New Menu Program' do? After
double clicking the executable file, NEW_MENU.PRG, the following screen will be
displayed.
![[Screen-shot: New Menu Program]](images/n_menu1.gif)
From
here the user can access the GEM menubar at the top
of the screen which allows you to do the following;
![[Screen-shot: /|\ menu]](images/n_menu2.gif)
|
'About
NEW MENU...' displays a dialog box which
provides details about the program.
|
![[Screen-shot: File menu]](images/n_menu3.gif)
|
'Open'
opens a GEM window. 'Close' closes
the open GEM window. 'Quit' exits the
program. |
![[Screen-shot: Options menu]](images/n_menu4.gif)
|
'Dim
Me' disables the menu item. 'Check Me'
toggles a tick on/off. 'Notes...' displays
another alert dialog. |
Selecting the 'Open' menu item under the 'File' menu
opens a GEM window similar to the one shown below.
![[Screen-shot: Test Window]](images/test_win.gif)
The
user is able to interact with the GEM window thanks
to the DO...LOOP subroutine (detailed in the source
code). Whenever the user interacts with the GEM window,
a window event is triggered which results in the following;
Window
Event |
Action |
CLOSE |
Closes the GEM window |
TITLE |
Title bar |
FULL |
Toggles between full
size and previous window size. When switching
to full size, the contents of the GEM window
is redrawn. |
INFO |
I have set the 'Information
bar' to inform the user what the last function
carried out on the window was. |
SIZE |
Resizes the window.
As with correct conventions, a window will
only redraw if increased in size, not when
made smaller, although this feature can
be added by modifying the DoSizer() Function. |
MOVE |
The window can be
moved about the screen, although it is not
constrained to be completely within the
screen. |
TOPPED |
If you have XControl
in the desk accessories slot, you can switch
between it and our test window by clicking
on the appropriate title bar. |
LFARROW |
Left Arrow (disabled)
|
RTARROW |
Right Arrow (disabled) |
HSLIDE |
Horizontal Arrow
(disabled) |
UPARROW |
Up Arrow (disabled) |
DNARROW |
Down Arrow (disabled) |
VSLIDE |
Vertical Arrow (disabled) |
How does the 'New Menu Program' work Below
I have written a brief overview of how the 'New Menu
Program' works. For a more detailed explanation, please
read the source code provided which includes helpful
comments above most of the C commands which explain
what's going on.
![[Screen-shot: About dialog]](images/new_menu.gif)
A
brief overview is...
- Upon
execution, load RSC file. If an error occurs then
EXIT.
- Initialise
and display the menubar.
- Open
a virtual workstation (for window contents).
- Loop
until a window/menu event occurs. Upon a window/menu
event, execute the appropriate code. If the user
has not selected 'Quit', return to program loop.
- Close
any open windows, remove the menubar, close any
virtual workstations and clears the resource file
from memory.
- Returns
to the desktop.
Finally... Well,
this tutorial was a long time in happening. For next
time I'll consider having a look at using the slider
bars, or maybe a simple dialog box created using WERCS.
Bye for now.
Files |
- New
Menu Program archive
ZIP
archive containing:
- NEW_MENU.PRG (Executable)
- NEW_MENU.RSC (Resource
file for executable)
- NEW_MENU.C (Source code)
- NEW_MENU.H (Header file
produced by resource
editor)
- NEW_MENU.HRD (Header file
produced by resource
editor)
- NEW_MENU.O (Object code)
- NEW_MENU.PRJ (Project
file for Lattice C Compiler)
|
|
|