Important: The information in this document is obsolete and should not be used for new development.
Defining Your Own Control Definition Function
In addition to the standard controls (buttons, checkboxes, radio buttons, pop-up menus, and scroll bars), the Control Manager allows you to define new, nonstandard controls as appropriate for your application. For example, you can define a three-way selector switch, a memory-space indicator that looks like a thermometer, or a thruster control for a spacecraft simulator. Controls and their indicators may occupy regions of any shape, as permitted by QuickDraw.To define your own type of control, you write a control definition function, compile it as a resource of type
'CDEF'
, and store it in your resource file. (See the chapter "Resource Manager" in Inside Macintosh: More Macintosh Toolbox for more information about creating resources.) Whenever you create a control, you specify a control definition ID, which the Control Manager uses to determine the control definition function. 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. Thus, for a given resource ID and variation codecontrol definition ID = 16 x 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 define your own variation codes, which various Control Manager routines pass to your control definition function. This allows you to use one
'CDEF'
resource to handle several variations of the same general control.The Control Manager calls the Resource Manager to access your control definition function with the given resource ID. The Resource Manager reads your control definition function into memory and returns a handle to it. The Control Manager stores this handle in the
contrlDefProc
field of the control record. In 24-bit addressing mode, the variation code is placed in the high-order byte of this field; in 32-bit mode, the variation code is placed in the most significant byte of theacReserved
field in the control'sAuxCtlRec
record. Later, when various Control Manager routines need to perform a type-dependent action on the control, they call your control definition function and pass it the variation code as a parameter.If you create a control definition function, you can use control color table records of
any desired size and define their contents in any way you wish, except that part indices
1 through 127 are reserved for system definition. Note that in this case, you should allocate explicit auxiliary records for every control you create.
Subtopics
- MyControl