← More MAC Programming Techniques 1995

More MAC Programming Techniques 1995

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

Image 1

New Technology Building Blocks More MAC Programming Techniques DISK INCLUDED • Customize your Macintosh programs • Create file resources • Use custom controls • Includes examples in both Symantec C++ and Metrowerks CodeWarrior M&T BOOKS Dan Parks Sydow

A book cover with a dark and purple background, a large yellow-orange title, a bullet list on the left beside a floppy disk icon, and a photo of a keyboard, floppy disk, and abstract colored shapes on the right.

Reading notes: The small 'DISK INCLUDED' label and the M&T BOOKS logo text are small but appear legible; the 'New Technology Building Blocks' tagline is printed in spaced italic at the top and is read as a series label.

Printed product names
Symantec C++ · Metrowerks CodeWarrior
Languages
English
PDF page 1

New Technology Building Blocks More MAC Programming Techniques DISK INCLUDED • Customize your Macintosh programs • Create file resources • Use custom controls • Includes examples in both Symantec C++ and Metrowerks CodeWarrior M&T BOOKS Dan Parks Sydow

A book cover with a dark purple and black background, large yellow-orange title type, a floppy disk icon, bulleted feature list, and a photo of a keyboard and floppy disks in blue, pink and orange tones.

Reading notes: Small logo text on the M&T Books mark is stylized and may not be fully legible; 'M&T BOOKS' reading is inferred from the logo.

Printed product names
Symantec C++ · Metrowerks CodeWarrior
Languages
English
PDF page 2

The image is a plain, blank white page with no visible artwork, text, or layout elements.

Reading notes: The image appears entirely blank with no visible text, so the transcript and printed fields are empty.

PDF page 3

Contents Introduction .................................................... 1 What's on the Disk .............................................................................. 2 What You Need .................................................................................... 3 Why This Book is for You .................................................................... 3 Chapter 1: Custom Menus and the MDEF......... 5 The MDEF and Menu Definition Procedure .................................... 6 Setting the MDEF ID of a MENU Resource ................................. 7 The MDEF Defines the Look and Actions of a Menu ................. 8 Creating and Using an MDEF Code Resource ........................... 11 The MDEF Source Code ................................................................... 14 The Menu Definition Procedure Entry Point ............................ 15 Taking Care of the Preliminaries .. .. .. .. .. ... .. .. .. .... ... .. .. .. .... .. .. ... .. .. . 19 Handling an mSizeMsg Message ................................................. 22

Languages
English
PDF page 4

More Mac Programming Techniques Handling an mDrawMsg Message ............................................... 23 Handling an mChooseMsg Message ........................................... 27 The MyMDEF Source Code Listing ............................................ 34 Building the MDEF Code Resource ................................................. 37 Building with CodeWarrior ......................................................... 39 Building with Symantec C++ /THINK C ..................................... 40 The MDEF Test Application ............................................................. 42 What the Test Application Does .................................................. 43 The Test Application Resources .................................................. 43 The Test Application Source Code ............................................. 4 7 Cl1apter Summary ............................................................................. 55 Chapter 2: Custom Controls and the CDEF .... 57 The CDEF and Control Definition Function .................................. 58 Setting the CDEF ID of a CNTL Resource ................................. 59 The CDEF Defines the Look and Actions of a Control .................. 62 Tl1e CDEF Source Code .................................................................... 63 The Control Definition Function Entry Point ........................... 64 Taking Care of the Preliminaries ................................................ 67 Handling a testCntl Message ....................................................... 71 Handling a drawCntl Message ..................................................... 74 The MyButtonCDEF Source Code Listing ....................................... 84 Building the CDEF Code Resource .................................................. 88 Building with Code Warrior ......................................................... 88 Building with Symantec C++/THINK C ..................................... 90 The CDEF Test Application .............................................................. 92 V\'hat the Test Application Does .................................................. 92 The Test Application Resources ....................................................... 95 The Test Application Source Code ........................................... 102 Adding a Second Button to MyTestApp ......................................... 108 Changing the MyTestApp Resource File .................................. 108 Building a New MyTestApp Application ................................... 110 Adding Control Variation Handling to MyButtonCDEF .............. 112 vi

Reading notes: Source appears to be a table of contents; page numbers and dot leaders are not body text.

Languages
English
PDF page 5

Contents Changing the MyTestApp Resource File .................................. 112 The CDEF Source Code for Control Variations ....................... 115 Adding More Control Variations to a CDEF ............................ 123 Chapter Summary ........................................................................... 125 Chapter 3: More Custom Controls: Sliders .... 127 The CDEF and Slider Controls ...................................................... 128 Drawing the Slider Control and Indicator ............................... 128 The Slider Resources ... .. .. .. .. ..... ... .. ....... .. .. .. ... ... .. ... ... .. .. .. .. . .. .. .. .. 131 Slider Control Source Code .... .... .. .. .. .. ... .. .. .. .. .. .. .. .. .. .. .. .. ... ... .. ... .. .. . 134 The Slider CDEF Entry Point .................................................... 135 Taking Care of the Preliminaries .............................................. 138 Calculating the Thumb Rectangle ............................................ 139 Handling a testCntl Message ..................................................... 144 Calculating the Thumb Region ................................................. 145 Handling a thumbCntl Message ............................................... 148 Handling a posCntl Message ..................................................... 155 Handling a drawCntl Message ................................................... 159 Building the CDEF Code Resource .......................................... 161 The Slider Test Application ............................................................ 161 The Test Application Resources ................................................ 162 The Test Application Source Code ........................................... 164 Sliders and Custom Dragging ......................................................... 166 The CDEF Messages ................................................................... 166 Handling a dragCntl Message ................................................... 168 Smoother Custom Dragging ........................................................... 174 Adding New PICT Resources .................................................... 174 Taking Care of the Preliminaries .. .. .. .. .. .. .. .. ... ... .. .. .. .. ... .. .. ... .. .... 177 Handling a dragCntl Message ................................................... 178 Handling a drawCntl Message ................................................... 180 Covering the Old Thumb .......................................................... 183 Adding a Label to the Control .................................................. 185 Chapter Summary ........................................................................... 187 vii

Languages
English
PDF page 6

More Mac Programming Techniques Chapter 4: Control Panels and cdevs .......... 189 Control Panels and the Finder ....................................................... 190 A Control Panel or an Application? .......................................... 193 (~011 trol Panel Resources ................................................................. 194 About the MySetSound Control Panel ..................................... 195 MySetSound and the Required Control Panel Resources ....... 198 MySetSound and the Familiar Resource Types ........................ 199 MySetSound and the nrct Resource Type ................................ 204 MySetSound and the mach Resource Type .............................. 209 Control Panel Source Code ............................................................ 211 Control Panels and Private Data Storage ................................. 211 The Control Device Function Entry Point ............................... 213 Taking Care of the Preliminaries .............................................. 215 Handling an initDev Message .................................................... 216 Setting the Radio Buttons .......................................................... 217 Handling a hitDev Message ....................................................... 221 The MySetSound Source Code Listing ..................................... 225 Building the cdev Code Resource .................................................. 227 Building with Code Warrior ....................................................... 229 Building with Syman tee C++ /THINK C ................................... 230 Enhancing the MySetSound Control Panel ............................. 232 Creating an Icon Family ............................................................ 234 Changing the Control Panel's Display Font ............................. 236 Additional Resources ................................................................. 238 Additions to the Source Code ................................................... 239 The MySetSoundPlus Source Code Listing .............................. 242 The Mylnsanity Control Panel ....................................................... 246 The Mylnsanity Resources ......................................................... 248 Handling a nulDev Message ...................................................... 252 Selective Execution: The mach Resource and the macDev Message ................................................................... 254 The Mylnsanity Source Code Listing ........................................ 257 Chapter Summary ........................................................................... 260 viii

Reading notes: Possible OCR errors: 'Mylnsanity' may be 'MyInsanity'; 'nrct' may be 'nrct' or 'nrct' resource type; '(~011 trol' likely 'Control'

Printed product names
MySetSound · MySetSoundPlus · Mylnsanity
Languages
English
PDF page 7

Contents Chapter 5: Resources................................. 261 About Resources .............................................................................. 262 Using Multiple DITL Resources in One Dialog Box .................... 263 About Dynamic Dialog Box Items ............................................. 263 The MulitpleDITLs Resources .................................................. 266 The AppendDITL() and ShortenDITL() Routines ................. 271 Keeping Track of DITL Items ................................................... 273 The MultipleDITLs Source Code Listing ................................. 276 Building the MultipleDITLs Program ...................................... 281 Using Custom Resource Templates ................................................ 282 The TemplateUser Program ...................................................... 284 Creating a New Resource Type and Template ......................... 285 Using Resource Data In an Application ................................... 294 The TemplateUser Source Code Listing .................................. 298 Chapter Summary ........................................................................... 300 Chapter 6: Resource Files . . .. .. . .. .. . .. . .. . .. .. .. .. 303 The MultipleRsrcFiles Resources .............................................. 307 Resource File Reference Numbers ........................................... 308 Opening and Closing a Resource File Source Code ................ 310 The MultipleRsrcFiles Source Code Listing ............................. 312 Dynamically Creating a New Resource File ................................... 316 The CreateRsrcFile Resources ................................................... 318 Resource File Creation Code .................................................... 319 The CreateRsrcFile Source Code Listing ................................. 323 Dynamically Copying a Resource to Another File ......................... 324 The RsrcCopier Resources ........................................................ 325 DetachResource() and ReleaseResource() Explained ............ 327 Resource Copying Code ............................................................ 334 The RsrcCopier Source Code Listing ....................................... 340 Working with a Preferences File ..................................................... 343 The PreflJser Resources ............................................................ 345 ix

Reading notes: Chapter heading and table-of-contents entries are interleaved with dot leaders; reading order is clear but page numbers are not dates. Possible OCR error: 'MulitpleDITLs' and 'PreflJser' may be misspellings of 'MultipleDITLs' and 'PrefsUser'.

Languages
English
PDF page 8

More Mac Programming Techniques Using a Preferences File to Set Dialog Box Items .................... 349 Chapter Summary ........................................................................... 366 Chapter 7: Files ......................................... 369 Opening a Ne\v Document ............................................................. 370 Windows and Document Records ............................................. 371 The NewDocument Source Code Listing ................................. 376 Opening an Existing PICT File ...................................................... 379 Reading and Displaying the Contents of a PICT File .............. 381 The OpenPICTfile Source Code Listing .................................. 385 Saving a Document to a PICT File ................................................. 390 Expanding the Document Record ............................................ 392 Saving a Document with "Save As" ............................................ 394 Saving a Document With "Save" ................................................ 402 The SavePICTfile Source Code Listing .................................... 403 Opening an Existing TEXT File ..................................................... 409 The Text Window Document Record ....................................... 411 Reading and Displaying the Contents of a TEXT File ............. 412 The OpenTEXTfile Source Code Listing ................................. 419 Saving a Document to a TEXT File ................................................ 423 Adding Text to a Document ...................................................... 424 Saving a TEXT Document with "Save As" ................................ 425 The Save TEXTfile Source Code Listing ................................... 430 Chapter Summary ........................................................................... 435 Chapter 8: Printing ..................................... 437 About Printing ................................................................................. 438 The Printer Resource File ......................................................... 438 The Printer Driver Resource ..................................................... 442 Printing Manager Functions ........................................................... 443 The Print Record ....................................................................... 444 The MinimalPrint Source Code Listing ................................... 444 The Basic Printing Manager Functions .................................... 445 x

Reading notes: Table of contents page numbers and dot leaders are present but not part of the headline or product data. Chapter headings contain a possible OCR error: 'Ne\v' appears where 'New' is likely intended.

Languages
English
PDF page 9

Contents Running MinimalPrint .............................................................. 450 Printing Pictures ........................................................................ 451 Printing a Document ...................................................................... 456 Walking Through PrintPICTdoc ............................................... 457 The PrintPICTdoc Source Code Listing ................................... 462 Multiple Windows and Printing ..................................................... 466 The PrintPICTdocll Resources ................................................. 467 The PrintPICTdocll Interface .................................................. 467 Handling Selections from the File Menu ................................. 470 The PrintPICTdocll Source Code Listing ................................ 4 73 Printing Dialog Item Text ............................................................... 481 The PrintDITLscreens Resources ............................................. 483 Printing Lines of Text Using Static Text Items ......................... 486 The PrintDITLscreens Source Code Listing ............................ 493 Chapter Summary ........................................................................... 500 Appendix A: Errors . .. .. . .. . .. . ... . ... .. . ... . .... .. . .... 501 Syman tee and Code Resource Errors ............................................. 501 ResEdit Crash While Working with CNTL Resources .............. 502 Slider Control Freezes in Built Application ............................. 503 Global Variables Don't Hold Values ......................................... 503 Strings Contain Garbage Characters ........................................ 505 Multisegment Project Error....................................................... 506 Metrowerks and Code Resource Errors ......................................... 508 ResEdit Crash While Working with CNTL Resources .............. 508 Slider Control Freezes in Built Application ............................. 510 Link Error: Illegal Single Segment 32-Bit Reference .............. 510 Global Variables Don't Hold Values ......................................... 511 Strings Contain Garbage Characters ........................................ 513 Multisegment Project Error ....................................................... 514 System Crashes: Errors at Runtime ................................................ 516 Routines Available Only in System 7 ......................................... 516 Index ......................................................... 5::1.!J xi

Reading notes: Index page number '5::1.!J' is garbled and uncertain

Languages
English
PDF page 10

ACKNOWLEDGMENTS Michael Sprague, Development Editor, M&T Books, for keeping things rolling smoothly. Stephanie Doyle, Production Editor, M&T Books, for a page layout effort that resulted in a great looking book. Peter Ferrante, Apple Computer, for another helpful technical edit, and for taking the time to test the software. Michael C. Amorose, Alamo Computer, for including his mach resource template on this book's disk. Jason Anderson, Beyond Midnight Software, for including his PictSize utility on this book's disk. Alessandro Levi Montalcini, for adding his shareware cdevEloper utility to the book's disk. John Holder, for including his shareware utility Resource Handler FKEY with this book's disk. Carole McClendon, Waterside Productions, for making this book happen.

Reading notes: Line-break hyphenation and spacing irregularities in source text may affect reading of some names.

Printed product names
PictSize · cdevEloper · Resource Handler FKEY
Languages
English
PDF page 11

Introduction Chapter 1 covers the MDEF-the menu definition procedure. An MDEF is a code resource, that is, compiled code that can be used by other appli- cations. Because the first four chapters of this book all deal with code resources, you '11 read a thorough description of code resources and defi- nition procedures in general, and then menu definition procedures in particular. This chapter has a detailed walk-through of the creation of an MDEF that displays patterns rather than text items, and of the test appli- cation that makes use of this MDEF. Chapters 2 and 3 describe the CDEF, or control definition function. This type of code resource can be used to add 3-D buttons of your own creation to any Mac program. In Chapter 2, you'll see an example that does just that. Chapter 3 continues the discussion of the CDEF using slid- ers in the example programs. Chapter 4 covers the cdev, or control device function. After building a cdev you'll have what's more commonly known as control panel-just like those under the Apple menu of any Mac. 1

Reading notes: Spacing irregularities in words such as "'11" and "cdev" may reflect OCR artifacts.

Languages
English