# Macintosh C Programming Primer, Volume II: Mastering the Toolbox Using THINK C — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-884345f6314775d8bc67d1fdb3ba3227af4e3b40e6e3b5677c79c07b43f556e6)

Macintosh C Programming Primer

Transcribed text:

DAVE MARK

Addison-Wesley

Macintosh® C Programming

Primer

Volume II

Mastering the Toolbox Using THINK C®

Image description: Book cover with a blue header band bearing the author name and publisher logo, large black serif title text, colorful cut-paper style letters spelling 'Primer' on pink, yellow, blue, purple, orange, and green squares, and a blue diagonal shape at the bottom left.

Reading notes: The word 'Primer' is set in colorful letter tiles; the letters P, r, i, M, e, R were read as one word and may be stylized.

Printed product names: Macintosh C Programming Primer · THINK C

Languages: English

[Original Image 1](https://www.vintageapple.net/files/a20b1c8e9dd9394c6c5bc51db3acb6ed802524c28e510d876a386d434efb171a/db3bf8832364e2b33a6a9355.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-30e9dc9bbf9212f5836c51a5c634133948c0833a50c5e3e0788856d5d7c1e162)

Macintosh C Programming Primer

Transcribed text:

Addison-Wesley
DAVE MARK
Macintosh® C Programming Primer
Volume II
Mastering the Toolbox Using THINK C®

Image description: Book cover with a blue header band holding the Addison-Wesley logo and author name, a large black serif title, colorful cut-paper letter blocks spelling 'Primer' in pink, yellow, blue, purple, orange, and green, and a blue diagonal shape at the bottom left behind the subtitle.

Reading notes: The subtitle words 'Mastering the Toolbox' overlap a blue diagonal shape, and 'THINK C' is partly obscured by it, so the exact rendering of 'THINK' is slightly uncertain. Volume number 'II' is read as Roman numeral II.

Printed product names: Macintosh C Programming Primer · THINK C

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-2e5e9bbd0ea66767e446c934c9af764310ec97e48f2bd8cb542e641cace803a9)

Macintosh®C Programming Primer

Transcribed text:

Macintosh®C
Programming
Primer
Volume II
Mastering the Toolbox
Using THINK C®
Dave Mark
• TT
Addison-Wesley Publishing Company, Inc.
Reading, Massachusetts   Menlo   Park, California   New York
Don Mills,   Ontario   Wokingham, England   Amsterdam   Bonn
Sidney   Singapore   Tokyo   Madrid   San Juan   Paris
Seoul   Milan   Mexico City   Taipei

Reading notes: The first title line reads 'Macintosh®C', which may be an extraction artifact, and the title is set against the 'Volume II' and 'Mastering the Toolbox' lines. A stray '• TT' appears above the publisher name and its meaning is uncertain. Transcript is intentionally empty because the exact extracted text is preserved separately; the other fields were filled from the supplied copy only. No advertised products, prices, or dates are present in the supplied copy; the only year-like content is absent, so printedDates is empty.

Languages: English

[Original PDF page 2](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-34d49a7852d530f1d1eb5d20b5da4d14d68ec5ed930d1d99e8ff11f48f7b2171)

Transcribed text:

Many of   the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where
those designations appear in this book, and Addison-Wesley
was aware of a trademark claim, the designations have been
printed in initial capital letters or all capital letters.
Under the copyright laws, this book may not be copied,   photo-
copied, reproduced, translated, modified, or reduced to any
electronic medium or machine-readable form, in whole or in
part, without the prior written consent of the publisher.
Library of Congress Cataloging-in-Publication Data
(Revised for vol. 2)
Mark, Dave.
Macintosh programming primer.
Includes index.
Bibliography: p.
Vol.   2 has title: Macintosh C programming primer.
Contents: [1] Inside the toolbox using THINK's
Lightspeed C -   v. 2. Mastering the toolbox using
THINKC.
1.   Macintosh (Computer) -   Programming.
2. C (Computer program language). I. Reed,
Cartwright. II. Title.
III. Title: Macintosh C programming primer.
QA76.8.M3M368 1989   005.265   88-34992
ISBN   0-201-15662-8
ISBN   0-201-57016-5
Copyright©   1990   by Dave Mark
All rights reserved. Printed   in   the United   States   of America.
Published simultaneously   in   Canada.
ISBN   0-201-57016-5
5   6 7 8 9   10   - MW - 949392
Fifth   printing, July 1992

Reading notes: Title spelling 'Macintosh C programming primer' vs 'Macintosh programming primer' differs across catalog entries 'THINKC' and 'THINK' may be the same product written differently

Printed product names: Lightspeed C · THINK · THINKC

Printed dates: 1989 · 1990 · 1992 · 88-34992 · July 1992

Languages: English

[Original PDF page 3](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-bc2908e96c7cfecae41caefc11e18c7105c7a3e7fe726edb2d6296eb5a6249c1)

Image description: The image is an entirely blank white page with no visible artwork, layout, or markings.

Reading notes: No visible text found; the page appears blank.

[Original PDF page 4](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-cd12063afceb22930bf8f443454b25bca299431cc68ad52178aab7031c2a5e3c)

Transcribed text:

Contents
Foreword   by   Scott   Knaster   ix
Preface   xi
Acknowledgments   xiii
1   Welcome Back   1
Volume   I in Review   3
Volume   II Topics   5
Chapter 2-Toolbox Techniques   5
Chapter 3-Code Resources   6
Chapter 4-Color QuickDraw   8
Chapter 5-TextEdit   11
Chapter 6-0bject Programming   12
Appendix A-Glossary of Terms   13
Appendix B-Source Code Listing   13
How to   Use   This Book   14
Ready, Set . . .   15
2   Toolbox Techniques   17
All About Pointers   19
Pointers Are Never Relocatable   22
The Macintosh Memory Layout   22
The   System   Space   23
The Application Space   23
v

Reading notes: The source appears to be a table of contents rather than advertising copy, so no headline, products, prices or dates are identified.

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-2e98ea950b8340c90c6fdae026392914f80cc6e7b98b4d2d78c728024c602a5a)

Transcribed text:

vi   Macintosh Programming Primer
The   Stack   25
The Application Heap   27
Handles, At Last!   29
Careful With That Handle, Eugene!
When To   Use   Handles   34
Miscellaneous Tips and Techniques   34
MoreMasters( ) and MoveHHI( )   35
Purgeable Blocks   35
Keeping Your Applications 32-bit Clean
Piggybacking Data on Your Windows
Calling Them,   So   They Can Call You
In Review   39
3   Code Resources   41
Specialized Code   43
The Common Thread   44
Chapter Programs   45
AFI, the Application Font INIT   46
AFI Resources   48
Creating the AFI Project   53
Walking Through the AFI   Source   Code
The AFI cdev   60
AFI cdev Resources   61
The cdev   Source   Code   67
Checking   Out   the AFI   edev   73
32
35
36
38
56
Walking Through the cdev   Source   Code   74
Writing Your   Own   MDEF   82
The MDEF Project and   Source   Code   83
Building Your MDEF   87
Building the MDEF Tester   88
Walking Through the PICT MDEF   Source   Code   100
Dialog Filter Procedures   106
Creating the   DLOG   Resources   107
Walking Through the   DLOG   Source   Code   115
In Review   121
4   Color QuickDraw   123
The Evolution of QuickDraw   125
Color QuickDraw and Indexed Devices   126
The CGrafPort and the CWindowPtr   128
What Machine Is the Program Running   On?   129
Keeping Track of Graphic Devices   131
The Pixel Image   132

Reading notes: Source text is a table of contents, so no advertised products, prices, or dates appear Page numbers and chapter titles run together in the extracted text

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-a5e8b88ef0c66c975034e1205888c01e39e67450b580a3abb378ccae26c2984a)

Transcribed text:

Contents   vii
The First Program: Colorlnfo   133
Colorlnfo Resources   133
Setting   Up   the   Project   135
Running Colorlnfo   140
Walking Through the Colorlnfo Source Code   141
The   Palette   Manager   149
Using   the   Palette   Manager   150
Palette   152
Palette   Resources   152
Setting   Up   the   Project   152
Running   Palette   159
Walking Through the   Palette   Source Code   159
Using   the Arithmetic Color Modes   167
Color'futor: Hands-on Color   167
Color'futor   Resources   169
Setting   Up   the   Project   170
Running Color'futor   184
Walking Through the   Color'futor   Source   Code   185
Working with Off-screen Drawing Environments   202
GWorld   203
GWorld Resources   203
Setting   Up   the   Project   203
Running GWorld   208
Walking Through the GWorld   Source   Code   208
In Review   215
5   TextEdit   217
Exploring TextEdit   219
Using   TextEdit   221
TextEdit Record   221
TextEdit Routines   224
Scrolling Text in TextEdit   227
Resizing the DestRect   228
TextEdit's   Private   Scrap   230
FormEdit   230
FormEdit Resources   232
The Code   242
Running FormEdit   270
Walking Through the FormEdit   Source   Code   271
In Review   311

Reading notes: Table-of-contents style text with OCR-like errors such as 'Colorlnfo' and 'Color'futor' where 'l' and 'Color'futor' may be misreadings. Reading order is uncertain for some lines with broken hyphenation or spacing, such as 'Color'futor: Hands-on Color'.

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-5fb3746e3b9c52a6005de66c0c04e607c44147c2ec2fce473ecc86042dc0c54e)

Transcribed text:

viii   Macintosh Programming   Primer
6   Object Programming   313
About   Object   Programming   315
The   Shaper   Application   316
An   Object   View of   Shaper   316
An   Example   317
Instance Variables and Methods   318
Creating   Some   Shape   Objects   319
Object   References   320
Shape's   Methods   322
Adding Subclasses   to   Shaper   323
CreateSquare ( ) versus CreateShape (   324
A   Second   Shape   Subclass   324
Object Classes Exist on Levels   326
More about Methods   327
The THINK Class Library   329
TCL Organization   330
The Visual Hierarchy   330
The Chain of Command   333
The   Switchboard   and the Bartender   335
Building an Application with the TCL   335
Art Class   336
TinyEdit   337
The   Starter   Application   338
MyStarter   340
Creating a Folder for   MyStarter   341
Changing CStarterDoc.c   342
Replacing   CStarterPane.c   344
Replacing   CStarterPane.h   347
Creating   CDragPane.c   347
Creating   CDragPane.h   350
Creating CMouse.c   351
Creating CMouse.h   354
Checking   Your   Work   355
Walking Through the MyStarter   Source   Code   357
The CMouse Object Class   366
In Review   371
Appendix A   Glossary   373
Appendix B   Code Listing   395
Index   497

Reading notes: Source is a table of contents with page numbers; no headline or product copy is present Some entries have spacing irregularities in the extracted text, such as 'CreateShape (' with a missing closing parenthesis

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-c249f0d7a70cafc9ab3a561c35f36d56dea4f8fcb2f817e47526a532bc31f8f4)

Transcribed text:

Foreword
Scott Knaster
Back in 1984, just after the end of the Pleistocene Era, it was
actually possible for one person   to   know   just   about everything there
was to know technically about a Macintosh. There was, after all, just
one model, the venerable but not venerated Macintosh 128K. In fact,
calling the Macintosh 128K the first member of a product line was
pretty much wishful thinking; after all, they didn't say ''World War I"
until the sequel came out.
But I digress (or just think of it as hypertext). For all its 64K of
ROM,   several hundred routines, and many storage options (you could
connect an external   at   inch disk   drive,   or not), the Macintosh
programmer's world was well-defined, and by today's standards, it
was graspable-you could get your   head   around it, as they used to
say here in California.
Things around here are a little bit different now, of course.
Chances are your Macintosh knows how to talk to one or two across
the room, and if you're really cool, probably a few hundred more
located somewhere between here and Indonesia. There are now well
over a thousand routines defined in the many versions of the   ROMs
that Apple's genius engineers have cranked out over the past few
years in between cans of Jolt cola and occasional minutes of sleep. It's
a rich and complex world for programmers of all stripes, both pro-
fessional and hobby varieties.
ix

Reading notes: Heading 'Foreword' and author line 'Scott Knaster' appear as document front matter, not a primary headline. Possible inline hyphenation and line-break artifacts in the body text, e.g. 'at   inch disk' and 'ROMs' spacing.

Printed product names: Macintosh 128K · Macintosh

Printed dates: 1984 · World War I

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-0c710d2ca35c6fe7c0cb8ec25d34dfd9947dc2681810895432bbd655b741313f)

Macintosh Programming Primer

Transcribed text:

x   Macintosh Programming   Primer
And that, at last, is where this book comes in. Not too long ago, I
was wondering (electronically) aloud why no one had written a
practical, up-to-date book about programming the Macintosh in C,
currently the most popular language among Macintosh programming
gurus. The answer, of course, was that there was a book like that.
Hiding behind the innocent guise of a primer was just such a volume,
with friendly presentation, thoroughness, and fun. That was Volume
I of the   Macintosh Programming   Primer,   predecessor of this book.
(Digression again: as you probably know, the folks who invented
the Macintosh planned on programmers using Pascal or assembly
language. At that time, C was for UNIX hackers and employees of
huge telephone companies. Pretty soon, though, the clamor for C
started, and the rest is history.   If   you have practical reasons for
avoiding C, such as the need for features available in another
language, you probably have no reason to switch. To those of you who
resist C for religious reasons, I'll point out that Pascal and C really
aren't so different. It's a little like those two guys with black and
white faces on   Star   Trek; they hated each other, but nobody else
could tell them apart. Language religion wars don't really help
anyone, but writing great software does.)
Anyway, Dave Mark sees all the neat new stuff in the Macintosh
world as his playground, and he invites us to play, too.   In   this
wonderful volume, we get to go exploring with Dave as he takes us on
a tour of many of the things that our new and improved Macintoshes
can do.   Some   of my favorite discussions include the ones about cdevs,
object programming, and the world of living color with Color
QuickDraw, but they're all entertaining. By choosing THINK C as
the learning tool, we can   all   easily sing along with Dave as we go.
This book is full of fun and good learning. With the vast landscape
of Macintosh programming as your goal and Dave Mark as your
friend, you'll soon feel the awe and mystery of commanding your
Macintosh to do great things.
Scott   Knaster

Reading notes: Running header 'Macintosh Programming Primer' may not be the primary heading of the page

Printed product names: Macintosh Programming Primer · THINK C · Color QuickDraw · Star Trek

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/1#scan-b1f3101a7393515d86758a376aa8e78c47bfa94c0905ae08561144bff5c2a904)

Transcribed text:

Preface
From the sounds of   it,   Macintosh   C   Programming Primer, Volume I   was
well received. Cartwright Reed and I got lots of letters, phone calls,
and AppleLinks, and all were much appreciated. People also sent us
personal letters relating their own programming experiences. We
even got Christmas cards!
We also received a bunch of letters from people with suggestions
for   Volume   II   of the   Primer.   These letters were the primary factor in
determining the table of contents for this book. Color QuickDraw,
Object   Programming, and TextEdit all made the cut-you asked for
it, you got it!
I   am very interested in hearing from you. Though you can write to me
in care of Addison-Wesley, the best way to get in touch with me is via
CompuServe's   Learn Programming   forum. Log in to CompuServe,
type:
GOMACDEV
then check out   Section   11. Whether you have questions or comments
about the   Primer   or just want to say hello, the   Learn Programming
forum is the place to be.
One   more thing. Please join me and millions of others in the cam-
paign to save our planet's natural resources. Recycling, conservation
of   water and gasoline, and reduced consumption of non-biodegradable
products are vital to that goal. I believe that together we   can   make a
difference.
D.M.
Arlington,   VA
xi

Reading notes: Preface text contains irregular spacing around some words, possibly from extraction.

Printed product names: Macintosh C Programming Primer, Volume I · Color QuickDraw · TextEdit

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/cf86a171fcf2506c6e6f993c7aa96f433146e7332fd53dd3cc2a9b4cd53701b9/Macintosh_C_Programming_Primer_1990.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1990-5bd26b/2.md)
