Monkey CDEV
Volume Number: 3
Issue Number: 9
Column Tag: C Workshop
CDEV Extends Control Panel 
By Jan Eugenides, Assembly Corner, Maynard, MA
The new control panel that comes with System 4.1 is extensible. You can write a
code resource called a ‘cdev’ to add functions to the control panel. The process is not
difficult, and it offers a number of interesting possibilities.
What I had in mind for this project was to write a fairly simple cdev, just to test
the waters. Having just acquired a Macintosh II, I also wanted to explore some of the
sound generation capabilities. The result is Monkey, an amusing addition to the control
panel. Although this particular cdev will only work on a Macintosh II (because it calls
the Mac II’s sound routines), the techniques shown here will work for more
generalized cdevs as well.
The Control Panel
Figure 1 shows the new Control Panel with the General panel displayed. The panel
allows choosing the Desktop pattern, setting the rate of insertion point blinking,
setting the time, and more. Some other standard panels allow setting keyboard options,
sound options, and display options.
By writing your own cdev, you can add a new icon to the scrollable list that
appears on the left edge of the Control Panel. In Figure 1, you can see the icon for the
Monkey cdev at the bottom. Clicking on an icon selects it, and the Control Panel
displays various controls, depending on the item list contained in the corresponding
cdev. Figure 2 shows how the Control Panel appears when Monkey is selected. Clicking
on the picture of a monkey causes the Macintosh II to generate the a monkey screech
sound.
How It Works
When the user opens the Control Panel, it scans the System Folder for all
resource files of type ‘cdev’. When it finds one, it loads the icon and the file’s name and
adds it to the icon list. After all the cdevs are loaded, the General icon is selected and
the standard controls are displayed. The Control Panel then calls the cdev with various
event messages, indicating which items the user has clicked or dragged, enabling the
cdev to track its controls.
A cdev file must contain eight resources:
• cdev - a code resource
• mach - some data that indicates which machines the cdev is compatible with
• DITL - a standard Dialog item list
• nrct - some data that defines the number of rectangles needed for the cdev’s
display, and their sizes.
• ICN# - a standard icon with mask
• BNDL - a standard bundle resource
• FREF - a standard file reference resource
• An owner resource, that must be a unique four-character identifier, just like the
ones used for applications. The Monkey cdev uses the type ‘mOnk’.
With the exception of the owner resource, all the resources should have the same
ID number, -4064. The owner resource ID depends on how the BNDL is structured,
and is usually zero.
Fig. 1 Adding our own control functions
The nrct and mach Resources