# 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-1989-cc031b/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-1989-cc031b/1#scan-41547fd2030bef54532c719fac54a431c5ef7db9450667e21c36fe92b84ab70c)

Macintosh C Programming Primer

Transcribed text:

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

Image description: A book cover with a blue header bar bearing the Addison-Wesley logo and author name, a large black serif title with the word Primer spelled in colorful cut-out letter tiles (pink P, orange r, blue i, purple M, orange e, green R), and a blue-scribbled shape at the lower left behind the subtitle text.

Reading notes: The blue shape at lower left partially overlaps the word THINK in the subtitle, so 'THINK' is partly obscured and read from context. The 'Volume II' line is in blue while the subtitle below is black; reading order follows top-to-bottom layout. The 'Primer' letter tiles are stylized and partly overlap each other; letters were read as P, r, i, M, e, R.

Printed product names: Macintosh · THINK C

Languages: English

[Original Image 1](https://www.vintageapple.net/files/6d1d5fbabbe19782e8dec5af58d4cd2220fc7b0df7132a755e535f1265dcc2d3/4a7a2856843643a62882c8cb.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-8eae62426f94110609dde2525901758a4fe82e68304ffecea96664ab7da3a844)

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 top band showing the Addison-Wesley logo and author name, large black title letters with the word Primer set in multicolored tilted paper-like blocks (pink, yellow, blue, purple, orange, green), and a blue diagonal shape in the lower left behind the subtitle.

Reading notes: Subtitle text 'Mastering the Toolbox Using THINK C' is partly overlapped by the blue shape in the lower left; the letters 'THINK C' are legible but the overlap reduces clarity. Reading order of the title lines is inferred from layout.

Printed product names: Macintosh C Programming Primer · THINK C

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-c06d9095115ae01b2e61f79dad767bd40eebf24754907486c7f9e9a5a69be23d)

Macintosh®C Programming Primer

Transcribed text:

Macintosh®C
Programming
Primer
Volume   II
Mastering the Toolbox
Using THINK C®
Dave Mark
• ......
Addison-Wesley Publishing Company, Inc.
Reading, Massachusett,s   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: Possible OCR error: 'Massachusett,s' appears with a stray comma. Line-break and reading order of publisher city list is uncertain.

Printed product names: Macintosh®C · THINK C®

Languages: English

[Original PDF page 2](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-e70b160b1c836e3211c513b8c44a56254e4f94d55f068d9f0397220e730d4fc4)

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
4 5 6 7 8 9   10   -   MW   -   94939291
Fourth printing, November 1991

Reading notes: Printed catalog numbers and ISBN digits may be garbled by extraction spacing Some product designations split across lines in the front matter

Printed product names: Lightspeed C · Macintosh

Printed dates: 1989 · 1990 · November 1991 · 88-34992

Languages: English

[Original PDF page 3](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-b2f1d595d52c10b0af6edffe309fc59182b197cdc4e787f71d72d282cc97bcc4)

Transcribed text:

To Deneen and my father,
both of whom reached milestones this year.

Image description: A mostly blank white page with two lines of italic serif text centered on the left-middle area and a thin vertical gold line running down the right side.

Reading notes: Reading order is top-to-bottom as printed; no headline is present.

Languages: English

[Original PDF page 4](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-b9a7eb7acc9be15935b14832061db6b9dd892fe7feb22525a73981d99c63a655)

Transcribed text:

Contents
Foreword   by Scott Knaster   ix
Preface   xi
Acknowledgments   xm
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: Table of contents layout and page numbers may not reflect original reading order

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-cca010b79b92f131464fbee7e0cceae0cca017ec4e8e349bc072f15b8027e6cd)

Macintosh Programming Primer

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
32
35
36
38
Walking Through the AFI Source   Code   56
The AFI cdev   60
AFI cdev Resources   61
The cdev Source   Code   67
Checking   Out   the AFI cdev   73
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

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-46bbe4ac50f61924353b4270b4f2dc9409738075e8fff5e91ff80da79a801d4b)

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
ColorTutor: Hands-on Color   167
ColorTutor Resources   169
Setting   Up the Project   170
Running ColorTutor   184
Walking Through the ColorTutor   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: Source appears to be a table of contents with OCR artifacts (e.g., 'Colorlnfo' likely 'ColorInfo', 'Setting   Up' spacing). Reading order of fragmentary headings may be uncertain.

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-182c4b2b72b3a287d09406a29ec28165803da17066aa17990ad1f1bb830b1288)

Transcribed text:

viii   Macintosh Programming Primer
6   Object   Programming   313
About   Object   Programming   315
The Shaper Applicaticm   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   34   7
Creating CDragPane.c   34   7
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: Table-of-contents style text with OCR-like spacing artifacts such as 'Applicaticm' and split words like 'CreateShape (' and '34 7' Primary heading not explicitly printed in the supplied copy

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-f61a8ad4364cfbb72c0feb712d22e4e6c2a2e4700820408097a3ab4c5d935be5)

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   3-t   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: Phrase 'Pleistocene Era' is a figurative reference rather than a dated date; 'Indonesia' and 'California' are place references only. Inline text contains a hyphenated line break 'pro-fessional' that may be a typesetting artifact.

Printed product names: Macintosh 128K · Macintosh · Jolt

Printed dates: 1984

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-2a2b1dd916abebda7d773b5b693b6e95005aba96bc0220d9829d23c2604ed221)

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: The source contains a foreword-style passage with an apparent inline digression; reading order is continuous but intentionally interjected.

Printed product names: THINK C · Color QuickDraw · Pascal · C · Star Trek · UNIX · Macintosh

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-macintosh-c-programming-primer-1989-cc031b/1#scan-27dfe00e7ec4d59eaa67f52a5c7ef2314aa0255a4fa75db78cee3b1ca29700d7)

Transcribed text:

Preface
From the sounds of it,   Macintosh 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. Feel free to send me your
comments on Volume II, good or bad. I'd also love to see examples of
your work. Has anyone built an application that's on the market, or
being regularly used? Keep in touch. As always, send all letters,
comments, and cards (especially baseball cards-I love those!) to:
Mac Primer   Comments
2534 North Jefferson   Street
Arlington, VA 22207
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: Several words are split by hyphenation or line breaks, such as 'cam-paign' and 'non-biodegradable', which may affect reading order.

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

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/61f6611bf28cf159936a406de4116a9471a2a8184c8a9dcd75f16f93cb1fd49d/Macintosh_C_Programming_Primer_1989.pdf#page=11)

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