Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Macintosh Toolbox Essentials /
Chapter 5 - Control Manager / Introduction to Controls


The Control Definition Function

A control definition function determines how a control generally looks and behaves. Various Control Manager routines call a control definition function whenever they need to perform some control-dependent action, such as drawing the control on the screen.

Control definition functions are stored as resources of type 'CDEF'. The System file includes three standard control definition functions, stored with resource IDs of 0, 1, and 63. The 'CDEF' resource with resource ID 0 defines the look and behavior of buttons, checkboxes, and radio buttons; the 'CDEF' resource with resource ID 1 defines the look and behavior of scroll bars; and the 'CDEF' resource with resource ID 63 defines the look and behavior of pop-up menus. (If you want to define nonstandard controls, you'll have to write control definition functions for them, as described in "Defining Your Own Control Definition Function" beginning on page 5-109.)

Just as a window definition function can describe variations of the same basic window, a control definition function can use a variation code to describe variations of the same basic control. You specify a particular control with a control definition ID. The control definition ID is an integer that contains the resource ID of the control definition function in its upper 12 bits and a variation code in its lower 4 bits. For a given resource ID and variation code, the control definition ID is derived as follows:

control definition ID = 16 * ('CDEF' resource ID) + variation code

For example, buttons, checkboxes, and radio buttons all use the standard control definition function with resource ID 0; because they have variation codes of 0, 1,
and 2, respectively, their respective control definition IDs are 0, 1, and 2.

You can use these constants to define the controls provided by the standard control definition functions:
ConstantControl
definition ID
Control
pushButProc0Button
checkBoxProc1Checkbox
radioButProc2Radio button
scrollBarProc16Scroll bar
popupMenuProc1008Pop-up menu

The control definition function for scroll bars figures out whether a scroll bar is vertical or horizontal from a rectangle you specify when you create the control.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996