home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / document / csmprogr.txt < prev    next >
Internet Message Format  |  1992-11-05  |  59KB

  1. Date: Tue, 17 Mar 1992 0:24:21 PST
  2. From: Bill Lipa <lipa@camis.stanford.edu>
  3. Subject: Comp.sys.mac.programmer FAQ
  4.  
  5. Newsgroups: comp.sys.mac.programmer
  6. Subject: *** FAQ 02/26/92 *** Frequently Asked Questions (Read Me First!)
  7. Summary: Frequently Asked Questions list for comp.sys.mac.programmer
  8. Followup-To: 
  9. Distribution: world
  10. Organization: University of Oregon Computer and Information Sciences Dept.
  11. Keywords: frequently asked questions faq
  12.  
  13.  
  14. *****************************************************************************
  15.  
  16. Frequently Asked Question (FAQ) Posting                  This version written
  17. For newsgroup: comp.sys.mac.programmer                      February 26, 1992
  18.  
  19.   This file is automatically posted on the first of each month to comp.sys.
  20. mac.programmer.  It is also available via anonymous ftp from ftp.cs.uoregon.
  21. edu (user name 'anonymous', your internet address as password) in the
  22. directory /pub/mac.
  23.  
  24.   This file is maintained by Michael A. Kelly.  He can be reached at the
  25. following addresses:                                                         
  26.   
  27.    Internet:  mkelly@cs.uoregon.edu
  28.    SnailMail: Computer Science Dept.
  29.               University of Oregon
  30.               Eugene, Oregon  97403
  31.  
  32.   The purpose of this posting is to answer some of the most common questions
  33. asked on this group, and to refer people left with unanswered questions to
  34. available sources of additional help.
  35.  
  36.   Submissions, comments, etcetera, should be sent to Michael Kelly, as above.
  37. All such material sent will be considered to have entered the public domain
  38. (and will be subject to editing) unless specific text to the contrary
  39. accompanies the message (which may render the submission unusable).
  40.  
  41. *****************************************************************************
  42.  
  43. Contents:
  44.  
  45.    Changes
  46.  
  47.    Development Software
  48.       Compilers
  49.       Debuggers
  50.       Other Tools
  51.    
  52.    Apple Developer Programs
  53.       The Associates and Partners Programs
  54.       Apple Developer University
  55.       APDA
  56.       Developer CDs
  57.  
  58.    Other useful sources / wells of information:
  59.       Books and Periodicals
  60.       Usenet Mac Programmer's Guide (UMPG)
  61.       Kent Sandvik's Frequently Asked MPW C++ and MacApp Questions
  62.  
  63.    FTP sites
  64.       ftp.apple.com [130.43.2.3]
  65.       sumex-aim.stanford.edu [36.44.0.6]
  66.       rascal.ics.utexas.edu [128.83.138.20]
  67.       mac.archive.umich.edu [141.211.164.153]
  68.       comp.binaries.mac [newsgroup]
  69.  
  70.    One-liners: Aphorisms for our times
  71.  
  72.    Specific Questions Answered:
  73.       (1) How do you tell if a specific key is being pressed?
  74.       (2) How do you get a full pathname?
  75.       (3) How could anyone love the File Manager?
  76.       (4) When do you put an ellipsis on the end of a menu item?
  77.       (5) How do you set the SFGet/PutFile directory?
  78.       (6) Why does malloc/calloc keep crashing or returning NULL in Think C?
  79.       (7) How can I get millisecond timing from the keyboard (or mouse)?
  80.       (8) How do you put a border around the default button in a dialog?
  81.       (9) How do I go about writing serial port communications?
  82.      (10) How do I get the menubar to disappear and re-appear?
  83.      (11) How do I write an INIT?
  84.      (12) How do you access the application's data fork?
  85.      (13) What is the fastest way to paint one pixel on the screen?
  86.      (14) How do you draw directly into a pixmap without using QuickDraw?
  87.      (15) How do you draw directly onto the screen without using QuickDraw?
  88.      (16) How do you register signatures and file types with Apple?
  89.      (17) What RGB value does the system use for dimmed buttons, menus and
  90.              window titles?
  91.      (18) What's the difference between the resource ID of a 'MENU' resource
  92.              and the menuID field of that resource?
  93.      (19) When should I call MoveHHi?
  94.    
  95.    Eternal Debates:
  96.       Why doesn't the Mac do preemptive multitasking?
  97.    
  98.    Credits / Acknowledgements
  99.    
  100.  
  101. *****************************************************************************
  102.  
  103.  
  104.  
  105. Changes
  106.  
  107.    Added numbers to the Specific Questions Answered.  If you see a question
  108.       posted to c.s.m.p. that is answered in this file, please refer the
  109.       inquirer to Question #x in the FAQ.
  110.    Added Specific Questions Answered #19.
  111.    Replaced the review of Development Software:Debuggers:TMON.
  112.    Added the review Development Software:Other Tools:Resourcerer.
  113.    Plus one- or two-line updates/typo fixes to the following:
  114.       Development Software:Compilers:Think
  115.       FTP sites:rascal.ics.utexas.edu
  116.       One-liners:Resources
  117.       One-liners:Drawing
  118.       One-liners:Menus
  119.       Development Software:Debuggers:MacsBug
  120.       Specific Questions Answered #2, #3, #4, #6, #8, #12, and #17.
  121.          
  122.  
  123. *****************************************************************************
  124.  
  125.  
  126.  
  127. Development Software
  128.  
  129.    This is by no means a complete analysis of the tools, development systems,
  130.    etc. that are available.  This is a short list of things which *most* Mac
  131.    programmers use (or are at least aware of, and have considered using).
  132.  
  133.     
  134.    
  135.    Compilers
  136.    
  137.       Macintosh Programmer's Workshop (Apple)
  138.       
  139.       MPW is a package which contains separately-purchaseable compilers
  140.       for Assembly, C, C++, and Object Pascal.  All of these run in an
  141.       environment called the MPW Shell.  The Shell is a command-line
  142.       oriented environment, designed for extreme configurability with
  143.       scripts, user-writeable "tools", i/o redirection, and lots of
  144.       other bells and whistles.  On the pro side, it can do many things
  145.       that THINK cannot do; it scales much better to large projects; it can
  146.       be customized much more; and it's Apple's supported development
  147.       environment.  On the con side, it is comparatively expensive, slow,
  148.       and difficult to learn.  A debugger (SADE) is available for it, and
  149.       is philosophically similar to MPW.  An object library is available
  150.       (MacApp) which allows applications to be built on an object-oriented
  151.       framework, again similar to MPW in it's approach of being very powerful,
  152.       but not necessarily easy to learn, easy to use, small, or fast.
  153.       
  154.       MPW is also available on the quarterly Essentials-Tools-Objects CD-ROM
  155.       from Apple.  This disc contains the latest version of the entire MPW
  156.       development environment, as well as debugging utilities and a huge
  157.       collection of sample source code.  This brings the price of the MPW
  158.       environment down a bit, but it's still much more expensive than THINK.
  159.       
  160.       
  161.       Think (Symantec)
  162.       
  163.       Think is two separate products, Think C and Think Object Pascal.
  164.       They are similar products.  Both are integrated editor/compiler/
  165.       linker/debugger environments.  Both come with a large library
  166.       of predefined classes (the C classes are written in a sort of
  167.       pseudo C++ language that is Symantec's own Object C, not C++).
  168.       Think Pascal is MacApp-compatable, as well.  Both support inline
  169.       assembly, but there is no separate assembler.  Their main selling
  170.       point, however, is that they are very fast and very simple.
  171.       They are ideal for small projects that you want to finish in a
  172.       few days, for beginners, and for people who need a full-fledged
  173.       development environment but cannot afford MPW.  This is not to say
  174.       that the Think environments are not useful for commercial development;
  175.       many successful commercial programs were written with Think.  The
  176.       difference in power between MPW and Think is only noticeable with
  177.       very large and/or multiple-developer projects.
  178.    
  179.    
  180.    
  181.    Debuggers (beyond SADE and the Think debuggers)
  182.       
  183.       
  184.       MacsBug (Apple)
  185.       
  186.       MacsBug is an assembly-level debugger.  It is a command-line
  187.       driven, entirely text-based environment which uses little of
  188.       the Mac toolbox, and is thus fairly stable in crashes (although
  189.       it doesn't use protected memory, its main failing in the area
  190.       of stability).  It supports complex operations with breakpoints,
  191.       A-line traps, macros, expressions, and more, and can be configured
  192.       even more with user-writeable 'dcmd' external code resources.  MacsBug
  193.       is free via anonymous ftp from ftp.apple.com.  It is also included with
  194.       the book "Debugging Macintosh Software with MacsBug."
  195.       
  196.       
  197.       TMON Professional (ICOM)
  198.       
  199.       TMON Professional is an object-level debugger which is MUCH more
  200.       powerful than MacsBug.  It has an elaborate interface which looks
  201.       nothing like a Mac application, and takes a while to get used to.  It
  202.       is a very intelligent program, however, which can often display memory
  203.       in its most useful format without help (e.g. it will disassemble code,
  204.       and display a string as a string, automatically).  It has strong
  205.       support for types, allowing you to easily view complex structures,
  206.       arrays, floating point numbers, and more.  You can examine the stack,
  207.       the heaps, and just about anything else you could be interested in.
  208.       It also provides versatile scripting, and is amazingly configurable.
  209.       There are more goodies in this package than I can possible describe
  210.       here.  Drawbacks are high price, and a very steep learning curve.
  211.       
  212.       
  213.       The Debugger (Jasik Designs)
  214.       
  215.       The Debugger (also known as Jasik's Debugger, because it was written by
  216.       Steve Jasik) is the only source level debugger with all the low-level
  217.       features of Macsbug (speed, straight-forward display of important info)
  218.       and many of the advantages of source level debuggers (source code,
  219.       quick display of local variables).  Some of its best features are
  220.       complete support for Object Pascal, speed, and the ability to look at
  221.       resource map and file information.  You gotta love any debugger that
  222.       will display all of the low-level globals with their values in a single
  223.       keystroke!  It also has a On the down side, the interface is an aquired taste, the
  224.       documentation needs work and distribution disks lack a certain polish.
  225.       But, phone support is very good (you often get Steve himself).
  226.       
  227.       
  228.       SourceBug (Apple)
  229.       
  230.       This is similar to SADE, but I hear it is much nicer.  It is not
  231.       scriptable, however.  Perhaps someone would like to give me a review
  232.       of SourceBug to put here???
  233.       
  234.       
  235.       
  236.    Other tools
  237.       
  238.       
  239.       ResEdit (Apple)
  240.       
  241.       ResEdit is the accepted tool for editing and creating resources.
  242.       It has very little competition, partially because it is a very
  243.       good and comprehensive program, and partially because it is
  244.       free (available via anonymous ftp from ftp.apple.com).  It allows
  245.       you to edit any resource in hexadecimal, and most of the standard
  246.       types have special editors that provide a direct-manipulation paradigm
  247.       for editing them.  Users may write their own pickers and editors for
  248.       custom resource types, although this is rarely done in practice.
  249.       
  250.       
  251.       Resourcerer (Mathemaesthetics)
  252.       
  253.       Resourcerer is a commercially available replacement for ResEdit.  Many
  254.       developers use it exclusively, and swear by it quite vehemently.  This
  255.       is from one of them:
  256.       
  257.       RESORCERER is a no-holds-barred resource dynamo.
  258.         -- embarrasses the ResEdit dialog editor
  259.         -- supports many more template data types
  260.         -- swap in different resource templates based on a key value
  261.         -- creates recursive resources
  262.         -- generates starter code for a dialog
  263.         -- does complex searches against resource contents or titles
  264.         -- renumbers resources in batches
  265.         -- changes resource types
  266.         -- excellent support from the author himself
  267.       
  268.       
  269.       Virtual User (Apple)
  270.       
  271.       Virtual User allows you to script user interactions with a program so
  272.       that they cal be relayed over and over, and it can execute scripts
  273.       remotely, over AppleTalk.  So, for instance, you could write a script
  274.       that puts your program through its paces, and then automatically
  275.       execute that script simultaneously on lots of differently configured
  276.       Macintosh systems.  It is available from APDA (#M0987LL/B).
  277.             (This paragraph taken from develop Issue 8, page 60.)
  278.       
  279.       
  280.       Online Companion (Addison-Wesley)
  281.       
  282.       Online Companion is a reference tool.  Hit a magic key combination,
  283.       and a pseudo-window opens at the bottom of the screen which allows
  284.       you to type in a full or partial name and find it in Online's
  285.       database.  It contains Inside Mac and some supplements, Tech Notes,
  286.       etc.  It's fast and simple.
  287.       
  288.       
  289.       Think Reference (Symantec)
  290.       
  291.       Think Reference is a reference tool.  It is a hypertext version of
  292.       Inside Mac I-V and the Tech Notes.  Click on the function or data
  293.       type name to go to the page on which it is defined.  It includes
  294.       some very useful notes and examples written by Symantec, and the
  295.       function prototypes can be copied and pasted into your editor.
  296.       Very fast and simple to use.  But beware of typos and, in some cases,
  297.       bad advice.
  298.    
  299.  
  300. *****************************************************************************
  301.  
  302.  
  303.  
  304. Apple Developer Programs
  305.  
  306.  
  307.    The Associates and Partners Programs
  308.    
  309.    From the back cover of 'develop' Issue 7:
  310.    
  311.    The Associate's Program, Apple's mainstream program for commercial
  312.    developers, is a convenient and cost-effective way to get essential
  313.    technical and marketing information.  This program offers self-help
  314.    technical support, keeps you up to date with the latest products and
  315.    technical documentation, and gives you access to the Apple developer
  316.    community through AppleLink.  Associates also receive discounts on
  317.    equipment.  The Associates program is designed for commercial developers
  318.    and others involved in development projects, such as contract programmers,
  319.    training providers, authors, and system integrators.
  320.    
  321.    The Partners Program is open to Apple-selected commercial developers.  In
  322.    addition to receiving the same development information and tools as
  323.    Associates, Partners receive technical support via electronic mail.
  324.    Membership in the Partners program is limited to developers who directly
  325.    contribute to Apple's long-term product strategies and business objectives.
  326.    
  327.    Information about becoming an Apple Associate or an Apple Partner is
  328.    available from Apple.  Call Developer Programs at (408) 974-4897,
  329.    AppleLink DEVHOTLINE (devhotline@applelink.apple.com), or write
  330.       20525 Mariani Avenue
  331.       M/S 75-2C
  332.       Cupertino, CA  95014,
  333.    for information or an application for the Associates or Partners program.
  334.    Developers outside the U.S. and Canada should instead contact the Apple
  335.    office in their country for information about developer programs.
  336.    
  337.    
  338.    Apple Developer University
  339.    
  340.    From the back cover of 'develop' Issue 7:
  341.    
  342.    Apple Developer University provides training for all levels of Macintosh
  343.    programmers.  The hands-on classes give you experience using the most up-
  344.    to-date development tools.  Classes are offered in locations across the
  345.    United States, and on-site instruction can also be arranged.  Multimedia
  346.    self-paced courses are available from Developer University through APDA.
  347.    These courses include Macintosh Programming Fundamentals, User-Centered
  348.    Design, and Introduction to Object-Oriented Programming.
  349.    
  350.    The registrar at (408) 974-6215 can reserve your place or send a current
  351.    catalog.  You can also AppleLink DEVUNIV (devuniv@applelink.apple.com) or
  352.    write
  353.       20525 Mariani Avenue
  354.       M/S 75-6U
  355.       Cupertino, CA  95014
  356.    
  357.    
  358.    APDA
  359.    
  360.    From the back cover of 'develop' Issue 7:
  361.    
  362.    The Apple Programmers and Developers Association (APDA) offers convenient
  363.    worldwide access to development tools, resources, training products, and
  364.    information for anyone interested in developing applications on Apple
  365.    platforms.  A quarterly APDA catalog features over 300 technical products
  366.    from Apple and third-party developers.  There are no membership fees.
  367.    APDA offers convenient payment and shipping options, including site
  368.    licensing.  Apple Associates or Partners automatically receive the APDA
  369.    catalog.
  370.    
  371.    To order products or to receive a complimentary catalog,
  372.       (800) 282-2732 U.S.
  373.       (800) 637-0029 Canada
  374.       (408) 562-3910 International
  375.       (408) 562-3971 Fax
  376.       171-576        Telex
  377.       APDA           AppleLink (apda@applelink.apple.com)
  378.    
  379.       20525 Mariani Avenue
  380.       M/S 33-G
  381.       Cupertino, CA  95014
  382.    
  383.    
  384.    Developer CDs
  385.  
  386.    The developer CDs are available quarterly from APDA, or monthly to Apple
  387.    Associates and Partners.  The quarterly version is also included in the
  388.    quarterly issue of d e v e l o p.  They contain just about everything that
  389.    Apple makes freely available, including SpInside Mac, the Tech Notes, and
  390.    a plethora of code snippets.
  391.    
  392.  
  393. *****************************************************************************
  394.  
  395.  
  396.  
  397. Other useful sources / wells of information
  398.  
  399.  
  400.  
  401. Books and Periodicals
  402.  
  403.   
  404.    Technical Books
  405.    
  406.    
  407.       Inside Macintosh Volume I
  408.          Addison-Wesley.  ISBN 0-201-17731-5.  $24.95
  409.       Inside Macintosh Volume II
  410.          Addison-Wesley.  ISBN 0-201-17732-3.  $24.95
  411.       Inside Macintosh Volume III
  412.          Addison-Wesley.  ISBN 0-201-17733-1.  $19.95
  413.       Inside Macintosh Volume IV
  414.          Addison-Wesley.  ISBN 0-201-05409-4.  $24.95
  415.       Inside Macintosh Volume V
  416.          Addison-Wesley.  ISBN 0-201-17719-6.  $26.95
  417.       Inside Macintosh Volume VI
  418.          Addison-Wesley.  ISBN 0-201-57755-0.  $39.95
  419.       
  420.       Inside Mac is the definitive reference regarding the Macintosh
  421.       toolbox.  Volumes I and II are basically essential to any Mac
  422.       programmer who uses the toolbox at all.  Volume III is essentially
  423.       a summary, cross reference, index-y sort of thing, and isn't very
  424.       useful.  Volume IV is stuff specific to the Mac Plus and later
  425.       machines, which would make it almost as important as I and II (not
  426.       many 512K Macs left out there), except that the routines it
  427.       describes are not nearly as generally useful.  It does have all of the
  428.       stuff on the HFS File Manager, however, so if you're working with File
  429.       Manager routines you should definitely consult IV before I-III.  
  430.       Otherwise, you can survive without it for a while.  Volume V is the Mac
  431.       II volume.  It has everything on Color QuickDraw, as well as lots of
  432.       other goodies.  I'd say it's more useful than IV, but only if you're
  433.       doing color.  Volume VI is the System 7 volume.  It contains all kinds
  434.       of bizarre new things which are probably not of general use or
  435.       interest; but it contains a lot of new non-System-7 stuff as well (such
  436.       as 32-bit Quickdraw), and it has corrections to the other five volumes.
  437.       
  438.       
  439.       Inside Macintosh X-Ref, Revised Edition
  440.          Addison Wesley.  ISBN 0-201-57769-0.  $12.95.
  441.       
  442.       Inside Mac X-Ref is a cross-referenced index to the six volumes
  443.       and some other Macintosh technical books.
  444.       
  445.       
  446.       M68000 User's Manual
  447.          Prentice Hall.  ISBN 0-13-609249-7.  $22.95.
  448.       MC68020 User's Manual
  449.          Prentice Hall.  ISBN 0-13-567017-9.  $22.95.
  450.       MC68030 User's Manual
  451.          Prentice Hall.  ISBN 0-13-566423-3.  $22.95.
  452.       MC68881/MC68882 Floating-Point Coprocessor User's Manual
  453.          Prentice Hall.  ISBN 0-13-566936-7.  $22.95.
  454.       
  455.       The Motorola references are required reading for anyone doing
  456.       assembly programming on the Mac.  The 68000 is by far the most
  457.       important.  The 68881 manual only has relevance to those who
  458.       want to do floating point and don't want to use SANE (the Standard
  459.       Apple Numeric Environment, slow but robust, precise and general).
  460.       
  461.       
  462.       Technical Introduction to the Macintosh Family
  463.          Addison-Wesley.  ISBN 0-201-17765-X.  $19.95.
  464.       
  465.       This book provides an overview of the general hardware design, system
  466.       archiecture, and ROM design of the Macintosh.  It is not required for
  467.       programming, but does provide some useful background information for
  468.       programmers new to the Mac.
  469.       
  470.  
  471.       Programmer's Introduction to the Macintosh Family.
  472.          Addison-Wesley.  ISBN 0-201-19254-3.  $22.95.
  473.       
  474.       This book provides an overview of basic Macintosh programming
  475.       concepts.  It is recommended for programmers new to the Mac.
  476.       
  477.       
  478.       Guide to the Macintosh Family Hardware
  479.          Addison-Wesley.  ISBN 0-201-52405-8.  $26.95.
  480.       
  481.       This is the definitive guide to the hardware design of the
  482.       Macintosh family.
  483.       
  484.       
  485.       Designing Cards and Drivers for the Macintosh Family
  486.          Addison-Wesley.  ISBN 0-201-52404-X.  $26.95.
  487.       
  488.       This is the official guide for developers of expansion cards and
  489.       peripheral devices for the Mac.  This book is required reading for
  490.       anyone who wants to talk directly to expansion cards (video cards,
  491.       for example).
  492.       
  493.       
  494.       Human Interface Guidelines: The Apple Desktop Interface
  495.          Addison-Wesley.  ISBN 0-201-17753-6.  $14.95.
  496.       
  497.       This is the definitive guide to program interface design on the
  498.       Macintosh.  When you find yourself wondering where to put the OK
  499.       button in a dialog, consult this book.
  500.       
  501.       
  502.       Apple Numerics Manual
  503.          Addison-Wesley.  ISBN 0-201-17738-2.  $29.95.
  504.       
  505.       This book describes the Standard Apple Numerics Environment (SANE),
  506.       and provides information about the IEEE-standard arithmetic and
  507.       about the SANE engines on the Apple IIgs and Macintosh computers.
  508.       
  509.       
  510.       Inside the Macintosh Communications Toolbox
  511.          Addison-Wesley.  ISBN 0-201-57775-5.  $24.95.
  512.       
  513.       This is the definitive reference volume for the Communications
  514.       Toolbox.
  515.    
  516.    
  517.    
  518.    Teaching Books
  519.       
  520.       
  521.       Macintosh Programming Primer
  522.          Addison-Wesley.  ISBN 0-201-15662-8.  $24.95.
  523.       Macintosh C Programming Primer Volume II
  524.          Addison-Wesley.  ISBN 0-201-57016-5.  $24.95.
  525.       
  526.       These are excellent books for the beginning Mac programmer.  Both books
  527.       use Think C in their examples, but developers using other platforms
  528.       will find a plethora of useful tidbits.  I believe both books are
  529.       available in Pascal as well.
  530.       
  531.       
  532.       Macintosh Revealed, Volume One: Unlocking the Toolbox
  533.          Hayden Books.  ISBN 0-8104-6551-5.  $26.95.
  534.       Macintosh Revealed, Volume Two: Programming with the Toolbox
  535.          Hayden Books.  ISBN 0-8104-6561-2.  $26.95.
  536.       Macintosh Revealed, Volume Three: Mastering the Toolbox
  537.          Hayden Books.  ISBN 0-672-48402-1.  $26.95.
  538.       Macintosh Revealed, Volume Three: Expanding the Toolbox
  539.          Hayden Books.  ISBN 0-672-48413-7.  $26.95.
  540.  
  541.       This encyclopedic collection covers the entire Mac Toolbox for the
  542.       beginning Pascal or Assembly programmer.  It sometimes re-iterates
  543.       Inside Mac, but always offers a fresh perspective.  Volume I covers
  544.       basics including memory management and QuickDraw.  Volume II covers the
  545.       other essential Toolbox managers and exemplifies each by constructing
  546.       part of a complete text editor.  Volume III expands this application,
  547.       covering printing, drivers, desk accessories, sound and definition
  548.       functions.  Volume IV contains details of programming with MultiFinder,
  549.       Color QuickDraw and styled text.
  550.       
  551.       
  552.       How to Write Macintosh Software
  553.          Hayden Books.  ISBN 0-672-48429-3.  $28.95.
  554.          
  555.       This book gives comprehensive coverage of memory management and
  556.       debugging techniques.  It also gives an excellent overview of
  557.       assembly language programming on the Mac.  A must-have.  I hear that
  558.       it's out of print, though.
  559.       
  560.       
  561.       On Macintosh Programming: Advanced Techniques
  562.          Addison-Wesley.  ISBN 0-201-51737-X.  $24.95.
  563.       
  564.       This book contains a lot of information on all aspects of programming
  565.       the Mac, including hardware and software architecture, the toolbox,
  566.       and the use of assembly, C, and Pascal for programming the toolbox.
  567.       It includes quite a lot of source code.
  568.       
  569.       
  570.       Using the Macintosh Toolbox With C
  571.          Sybex.  ISBN 0-89588-572-7.  $29.95.
  572.       
  573.       This is a fairly good book for beginning Mac programmers.  Experienced
  574.       programmers will find nothing new here.
  575.       
  576.       
  577.       Programmer's Guide to MPW, Volume I
  578.          Addison-Wesley.  ISBN 0-201-57011-4.  $26.95.
  579.       
  580.       This is a basic introduction to using MPW.  I don't recommend it for
  581.       anyone who already uses MPW.
  582.       
  583.       
  584.       Programming with MacApp
  585.          Addison-Wesley.  ISBN 0-201-09784-2.  $24.95.
  586.       C++ Programming with MacApp
  587.          Addison-Wesley.  ISBN 0-201-57020-3.  $24.95.
  588.       
  589.       These give a basic introduction to programming with MacApp; the first
  590.       with Object Pascal, and the second with C++.
  591.       
  592.       
  593.       Elements of C++ Macintosh Programming
  594.          Addison-Wesley.  ISBN 0-201-55025-3.  $22.95.
  595.       
  596.       Just what the title says.  I haven't had a chance to look at it yet.
  597.       
  598.       
  599.       Programming for System 7.
  600.          Addison-Wesley.  ISBN 0-201-56770-9.  $26.95
  601.       
  602.       This is a guide to creating applications for System 7.  It describes
  603.       the new features and functions of the operating system in detail.
  604.       The sample code is in C and includes a complete System 7 application
  605.       in Chapter 1 which is expanded in succeeding chapters.
  606.       
  607.       
  608.       ResEdit Complete
  609.          Addison-Wesley.  ISBN 0-201-55075-X.  $29.95.
  610.       
  611.       Most of this book is not written for programmers, but includes quite
  612.       a bit of useful information nonetheless.  It contains detailed
  613.       discussions of using, customizing and programming ResEdit, including
  614.       the creation of custom templates, pickers and editors. It comes with
  615.       ResEdit 2.1 on disk, with sample source code in MPW C and Pascal.
  616.       
  617.       
  618.       Debugging Macintosh Software with MacsBug
  619.          Addison-Wesley.  ISBN 0-201-57049-1.  $34.95.
  620.       
  621.       This looks like a really good and useful book, but I haven't had a
  622.       chance to look at it yet.  MacsBug is included on disk, along with
  623.       several examples and dcmds.
  624.       
  625.       
  626.       Programming the M68000
  627.          Benjamin/Cummings.  ISBN 0-8053-5550-2.
  628.       680x0 Programming by Example
  629.          Howard W. Sams & Co.  ISBN 0-672-22544-1.  $17.95.
  630.       M68000 Assembly Language: Techniques for Building Programs
  631.          Addison-Wesley.  ISBN 0-201-11659-6.
  632.       The Complete Book of Macintosh Assembly Language Programming [sic]
  633.          Scott, Foresman & Co.
  634.          Vol I  ISBN 0-673-18379-3
  635.          Vol II ISBN 0-673-18583-4
  636.  
  637.       These are all assembly books that have been recommended by people on
  638.       the net.  The first two are general; the others are specific to the
  639.       Macintosh.
  640.    
  641.    
  642.    
  643.    Periodicals
  644.    
  645.    
  646.       d e v e l o p
  647.          Quarterly.  $10 per issue.  $30 per year.
  648.          develop
  649.          Apple Computer, Inc.
  650.          P.O. Box 531
  651.          Mt. Morris, IL  61054
  652.          AppleLink DEV.SUBS
  653.       
  654.       develop is Apple's technical journal for the Macintosh and Apple II
  655.       (the focus is on the Mac).  The articles are well-written and useful,
  656.       and it includes the Developer CD.
  657.  
  658.    
  659.       MacTutor
  660.          Monthly.  $5 per issue.  $40 per year Third Class; $55 First Class.
  661.          1250 N. Lakeview Suite O
  662.          Anaheim, CA  92807
  663.          (714) 777-1255
  664.       
  665.       The only Macintosh programming journal that I'm aware of.  A good
  666.       source of sample code.
  667.  
  668.        
  669.       
  670.    Usenet Mac Programmer's Guide
  671.  
  672.       The Usenet Mac Programmer's Guide (UMPG) is a collection of useful tips
  673.       culled  from comp.sys.mac.programmer.  Compiled by Matthew X. Mora
  674.       (mxmora@unix.sri.com), it is organized by topic and includes a table of
  675.       contents and index.  It is available via anonymous ftp from sumex-aim.
  676.       stanford.edu (36.44.0.6) in the directory /info-mac/tech/.
  677.    
  678.       It is also available in a pre-printed version, or on disk.
  679.    
  680.       To get a copy of the printed version send $17.00 to:
  681.             USENET Macintosh Programmer's Guide Printed Version
  682.             39075 Carmel Ct.
  683.             Fremont, CA  94538
  684.          
  685.       To get a copy of the disk version send $5.00 to:
  686.             USENET Macintosh Programmer's Guide Disk Version
  687.             39075 Carmel Ct.
  688.             Fremont, CA  94538
  689.    
  690.    
  691.    
  692.    Kent Sandvik's Frequently Asked MPW C++ and MacApp Questions
  693.    
  694.       This file is available upon request from ksand@apple.com or
  695.       via anonymous ftp to skinner.cs.uoregon.edu in the directory
  696.       /pub/mac.
  697.       
  698.       
  699.       
  700.       
  701. *****************************************************************************
  702.  
  703.  
  704.  
  705. FTP sites
  706.  
  707.  
  708.    ftp.apple.com [130.43.2.3]
  709.    
  710.       Contents
  711.          This archive contains just about everything available for free from
  712.          Apple.  Look here first for sample source code, the latest tech
  713.          notes, and tools such as ResEdit and MacsBug.  Very little of what
  714.          can be found here is available from other archives.
  715.  
  716.       Access
  717.          Anonymous ftp.
  718.          You should read the file /dts/README.FIRST before downloading from
  719.          this archive.  Everything for the Mac is in /dts/mac.  The 
  720.          moderators ask that you download during the off-peak hours if at
  721.          all possible, since this is just a IIci running A/UX.
  722.       
  723.       Submissions
  724.          You cannot post to this archive.
  725.       
  726.  
  727.    sumex-aim.stanford.edu
  728.    
  729.       Contents
  730.          This archive contains a large collection of public-domain and
  731.          shareware for the Mac.  It is well-maintained and updated regularly.
  732.          New submissions to the archive are listed every other day or so in
  733.          the newsgroup comp.sys.mac.digest.
  734.  
  735.       Access
  736.          Anonymous ftp.
  737.          Read the files in /info-mac/help for more detailed information
  738.          about the files in the archive.  Everything is in /info-mac.
  739.       
  740.       Submissions
  741.          Sumex accepts all submissions that "are of general benefit to
  742.          the Macintosh community."  Basically, if you have something that
  743.          you think is useful, and that other people may like to have, you
  744.          should feel free to send it to sumex.  All submissions should be
  745.          compressed and BinHexed, and should include a short but informative
  746.          blurb at the beginning of the file.  Mail your submissions to
  747.          info-mac@sumex-aim.stanford.edu.  Expect a delay of anywhere from
  748.          a week to a month before your file is made available.  For more
  749.          detailed information, consult the file /info-mac/help/posting-
  750.          guidelines.txt.
  751.  
  752.    
  753.    rascal.ics.utexas.edu [128.83.138.20]
  754.    
  755.       Contents
  756.          This archive contains most of what can be found at sumex.  Its
  757.          emphasis is on utilities and programming-related items, but it
  758.          contains quite a bit of other stuff as well.  It is the home of
  759.          the comp.sys.mac.announce archives.  Many items tend to appear
  760.          here before they show up at sumex or comp.binaries.mac.
  761.  
  762.       Access
  763.          Anonymous ftp.
  764.       
  765.       Submissions
  766.          Send submissions to macgifts@rascal.ics.utexas.edu (see Note below).
  767.          See Submissions for sumex for format description.
  768.   
  769.  
  770.    mac.archive.umich.edu [141.211.164.153]
  771.    
  772.       Contents
  773.          I haven't explored this archive yet, but I hear it has quite a bit
  774.          of general Macintosh freeware and shareware.  Perhaps someone more
  775.          familiar with this archive could send me a review....
  776.  
  777.       Access
  778.          Anonymous ftp.
  779.       
  780.       Submissions
  781.          More information to come....
  782.  
  783.    
  784.    comp.binaries.mac
  785.  
  786.       Contents
  787.          This is a moderated newsgroup for distribution of Macintosh freeware
  788.          and shareware.  Just about everything that gets sent to sumex and
  789.          the other major archives gets sent here as well.
  790.       
  791.       Access
  792.          Subscribe to the newsgroup....
  793.       
  794.       Submissions
  795.          All files should be compressed and binhexed for mailing.  Posting
  796.          to the newsgroup should automatically get your file mailed to the
  797.          moderator.  If this does not happen on your system, you can mail
  798.          your posting to the moderator yourself at macintosh@felix.uucp.
  799.          Expect a delay of as much as a month before your posting shows up
  800.          on the newsgroup.
  801.    
  802.    
  803.    
  804.    Note: To submit a file to sumex, rascal, umich, and comp.binaries.mac, it
  805.          is probably easiest to send it just to macgifts@rascal.ics.utexas.
  806.          edu.  Your file will then automatically get submitted to all four
  807.          archives.
  808.  
  809.  
  810.       
  811.       
  812.       
  813. ----------------------------------------------------------------------
  814.  
  815.  
  816.  
  817. One-liners
  818.  
  819.  
  820.  
  821. The Main Loop and Events
  822.  
  823. Call MaxApplZone and MoreMasters when the application starts up.
  824. If you call SetApplLimit, do it before calling MaxApplZone.
  825. Use HD in MacsBug while running to estimate how many times to call MoreMasters.
  826. Don't use SetEventMask to disable mouseUp events.  Better not to use it at all.
  827. Call WaitNextEvent if you're running under System 6 or later.
  828. DTS sample code passes 0x7fffffff to WaitNextEvent when nothing is happening.
  829. DTS sample code passes GetCaretTime() to WaitNextEvent when flashing a cursor.
  830. Call both GetNextEvent and SystemTask only if WaitNextEvent is unavailable.
  831. Call IsDialogEvents and DialogSelect even if GetNextEvent returns false.
  832. SetPort to a known good grafPort once every time through the event loop.
  833. Set the cursor on suspend and resume events.
  834. Call GetDblTime to get the maximum time for a double click.
  835. Measure double click time from mouse up to mouse down.
  836.  
  837.  
  838. Menus
  839.  
  840. Use SetItem to include meta characters literally in menus.
  841. Prepend an ASCII 0 to a menu item to use a leading '-'.
  842. Never make MENU resources purgeable.
  843.  
  844.  
  845. Resources
  846.  
  847. GetResource never produces resNotFound.  Check for a NIL handle instead.
  848. To create a resource file, call HCreate, then HCreateResFile.
  849. To open a resource file read-only for shared access, use HOpenResFile.
  850. Don't leave ResLoad set to false.
  851. GetResource on a dctb may return a non-resource copy of the dctb.
  852.  
  853.  
  854. Windows, Alerts, and Dialogs
  855.  
  856. Move and size windows to the bounding box of GetGrayRgn.
  857. Hide scroll bars when deactivating a window.
  858. Call DrawGrowIcon when activating or deactivating a window with a grow region.
  859. DrawGrowIcon does not check to see if the window has a grow region.
  860. Call PenNormal before calling DrawGrowIcon.
  861. itemHit will not be set when a dialog filter is called.
  862. Use a disabled UserItem to draw the roundrect outline around the OK button.
  863. ModalDialog assumes the dialog is already visible and in the front.
  864. Use screenBits.bounds to center dialogs, alerts, etc. below the menu bar.
  865. If you save window locations in files, they may not be valid for all monitors.
  866. DragWindow expects startPt in boundsRect; if not it may not call SelectWindow.
  867. SelectWindow does not automatically call SetPort.  You must do that yourself.
  868. DialogSelect responds to activate events but ignores suspend/resume events.
  869.  
  870.  
  871. Drawing
  872.  
  873. Always set the VisRgn and ClipRgn of offscreen ports.
  874. Set the ClipRgn first when making a picture.
  875. Don't make rowBytes in bitMaps greater than 8191.
  876. To dim text, draw a rectangle with penPat=gray and penMode=patbic over it.
  877. To draw rotated text, draw to an offscreen bitmap, rotate it, and CopyBits it.
  878. Don't use picSize to determine the size of a picture.  Check the handle size.
  879. Never draw outside a window except in XOR mode for temporary effects like drag.
  880. To avoid animation flicker, synchronize drawing to the vertical retrace.
  881. Lock handles to pictures before calling DrawPicture.
  882. CopyBits on more than 3Kb data will work, but it might have to allocate memory.
  883. The small Mac screen is 512 pixels wide by 342 pixels high including menu bar.
  884.  
  885.  
  886. Files
  887.  
  888. Don't write in the application file.  This will fail with read-only devices.
  889. Use PBGetVInfo to convert a VRefNum to a volume name.
  890. Delete uses the Poor Man's Search Path, so don't delete blindly.
  891. File Manager routines with dirID=0 use the Poor Man's Search Path.
  892. Truncate and reallocate files before overwriting to reduce fragmentation.
  893. Check/change the creator and type of Save As... files before overwriting.
  894. If you rewrite files by deleting and creating, copy all Finder information.
  895. Directory ID's are longs, not shorts.  Shorts work ALMOST all the time.
  896. Always set the version number that appears in some file manager calls to 0.
  897. To convert a pathRefNum to a name or file number, use PBGetFCBInfo.
  898. Prevent the creation of files with names that begin with a period.
  899.  
  900.  
  901. Interrupts and VBL Tasks
  902.  
  903. Don't call any Memory Manager routines during an interrupt.
  904. Unlocked handles may not be valid during an interrupt.
  905. To synchronize to the vertical retrace on Macs with slots use SlotVInstall.
  906.  
  907.  
  908. Handles and Pointers
  909.  
  910. Lock handles before passing their dereferenced pointers to any routine.
  911. Lock handles before setting referenced data to expressions containing functions
  912. Put an odd long at location zero on a 68000 to help find NIL handle references.
  913. Use HGetState/HLock/HSetState to lock a handle then put it back as it was.
  914.  
  915.  
  916. General
  917.  
  918. Always use unsigned characters within text and Pascal-format strings.
  919. Save application preferences in a folder named Preferences in the System Folder
  920. Use SysEnvirons to find the System (Blessed) Folder.
  921. Use GetAppParms to get the name of the application.
  922. The high bit of SysParam . volClik enables the alarm clock.
  923. Check the application name at $910 before exiting with ES within MacsBug.
  924. To exit to shell in the mini-debugger, enter SM 0 A9 F4 and then G 0.
  925. In Pascal, don't nest procedures to be passed by procedure pointer.
  926. In Pascal, "with theHandle^^" is unsafe if memory compaction can occur.
  927.  
  928.  
  929. Controversy Corner (Don't shoot me; I'm just the messenger.)
  930.  
  931. Avoid writing tail patches for traps.
  932. There is no official way to tell if MultiFinder is running or not.
  933.  
  934.  
  935.  
  936. *****************************************************************************
  937.  
  938. Specific Questions Answered
  939.  
  940.  
  941.  
  942. (1) How do you tell if a specific key is being pressed?
  943.  
  944.     Use GetKeys.  GetKeys fills a 16-byte KeyMap structure with the state of
  945.     every key.  Each bit represents a single key on the keyboard; 1 means the
  946.     key is down, 0 means it is up.  Note that there can be a maximum of seven
  947.     keys being pressed at a time - any of the modifier keys plus at most two
  948.     other keys.
  949.  
  950.     Here's an example in C:
  951.  
  952.     Boolean IsKeyDown(
  953.         unsigned short theKey )  // a keyboard-specific scan code for a key
  954.     {
  955.  
  956.         unsigned char  keyMap[16];
  957.  
  958.         GetKeys( (void *) keyMap );
  959.         return ((keyMap[theKey>>3] >> (theKey & 7)) & 1);
  960.  
  961.     }
  962.  
  963.  
  964. -----------------------------------------------------------------------------
  965.  
  966.  
  967. (2) How do you get a full pathname?
  968.  
  969.     Take a look at Tech Note #238, available from APDA (and other places).
  970.     It tells you everything you need to know to get a full pathname, and why
  971.     you should, in general, use a volume name, dirID, filename (and perhaps
  972.     volume creation date) triple instead.  Also check out the code snippets
  973.     available from ftp.apple.com et al.  There are a couple of snippets that
  974.     give code to get a full pathname, as well as many other cool file manager
  975.     tricks.
  976.  
  977.  
  978. -----------------------------------------------------------------------------
  979.  
  980.  
  981. (3) How could anyone love the File Manager?
  982.  
  983.     Its always those pesky wdrn's that are the problem.  Here is a
  984.     summary of some of the things to know:
  985.  
  986.     vrn = volume reference number
  987.           (small negative number; e.g. -2)
  988.     wdrn = working directory reference number
  989.            (large negative number; e.g. -32123)
  990.     dirID = directory ID
  991.             (small (but long integer!) positive number; e.g. 4123)
  992.            
  993.     - vrn's and wdrn's can be used interchangably for the most part.
  994.     - A vrn represents either a volume, or the root directory of a volume.
  995.     - A wdrn represents a directory on a volume.
  996.     - A dirID represents nothing without a vrn or a wdrn.
  997.     - A dirID overrides the directory otherwise specified by the vrn or wdrn
  998.       unless it's zero, in which case it's ignored.  If it is 2 it specifies
  999.       the root directory of the volume.
  1000.     - You should always use vrn,dirID pairs. To convert a wdrn into a
  1001.       vrn,dirID pair use GetWDInfo, which returns the vRefNum, the dirID and
  1002.       the procID of the wdRefNum.  The procID is almost always 'ERIK'.
  1003.     - You can also use GetVol/SetVol to convert volume names to/from vrns.
  1004.     - To store a vrn,dirID pair (between invocations of a program) convert
  1005.       the vrn to a volume name & creation date (for verification) and store
  1006.       them and the dirID (and a filename perhaps).
  1007.  
  1008.  
  1009. -----------------------------------------------------------------------------
  1010.  
  1011.  
  1012. (4) When do you put an ellipsis on the end of a menu item?
  1013.  
  1014.     Put an ellipsis (...) at the end of any menu item which requires more
  1015.     information in order to complete or simply displays information.  Usually
  1016.     this involves a dialog of some kind, be it modal or non modal.
  1017.  
  1018.  
  1019.  
  1020.  
  1021. -----------------------------------------------------------------------------
  1022.  
  1023.  
  1024. (5) How do you set the SFGet/PutFile directory?
  1025.  
  1026.     To set the directory that is displayed by SFGet/PutFile, stuff the
  1027.     volume reference number into SFSaveDisk, and the dirID into CurDirStore.
  1028.  
  1029.        CurDirStore = $398; Current dirID from Standard File (long)
  1030.        SFSaveDisk = $214; Negative of current vRefNum
  1031.  
  1032.  
  1033. -----------------------------------------------------------------------------
  1034.  
  1035.  
  1036. (6) Why does malloc/calloc keep crashing or returning NULL in Think C?
  1037.  
  1038.     #include <stdlib.h>
  1039.     Explanation:  In THINK C, parameters and return values are 2-byte ints
  1040.     by default, which causes the value passed to malloc to be $10000 times as
  1041.     large as you think it is, and causes the upper bytes of the return value to
  1042.     be zeroed.  Including stdlib includes a prototype which overrides the
  1043.     defaults.
  1044.     
  1045.     Another common cause of problems with malloc is overwriting the end of a
  1046.     string, such as only mallocing the size of the string and then writing
  1047.     the string plus a null into the malloc'd space.  Think's malloc algorithm
  1048.     stores block size information in space adjacent to the storage it
  1049.     allocates, so overwriting the storage tends to cause havoc. The problem
  1050.     may not show immediately since it will probably be the next malloc that
  1051.     encounters problems.
  1052.  
  1053.  
  1054. -----------------------------------------------------------------------------
  1055.  
  1056.  
  1057. (7) I'm writing a psychology experiment.  How can I get millisecond timing
  1058.     from the keyboard (or mouse)?
  1059.  
  1060.     The simple answer is that you can't.  Although the new time manager can
  1061.     call routines every couple of microseconds, input goes through the event
  1062.     manager, which only posts events about every 16 milliseconds.  Thus,
  1063.     even if you poll the keyboard every 30 microseconds, you will not get
  1064.     better than 16 ms. resolution.  If you really need millisecond accuracy,
  1065.     you need to use external hardware.
  1066.  
  1067.     The good news is that you probably don't need better than 16 ms.
  1068.     resolution anyway.  Measuring with 16 ms. accuracy only increases the
  1069.     standard deviation of your RT means by about 4.8 msec.  Read: Ulrich, R
  1070.     and Giray, M. (1989). Time resolution of clocks: Effects on reaction
  1071.     time measurement -- Good news for bad clocks.  British Journal of
  1072.     Mathematical and Statistical Psychology, 42, 1-12.
  1073.  
  1074.     By the way, there is a mailing list dedicated to running psychology
  1075.     experiments on the Mac.  It frequently gets tied up in arguments about
  1076.     millisecond timing.  The address to write to is:
  1077.        macpsych-request@stolaf.edu.
  1078.  
  1079.  
  1080. -----------------------------------------------------------------------------
  1081.  
  1082.  
  1083. (8) How do you put a border around the default button in a dialog?
  1084.  
  1085.     The most common way to do this is to create a dummy user item in the
  1086.     dialog, and use SetDItem to install a procedure that outlines the
  1087.     default button.  Here is an example in C:
  1088.     
  1089.       
  1090.       /* This function draws a border around dialog item #1 */
  1091.       
  1092.       pascal void OutlineDefault(
  1093.           DialogPtr theDialog;
  1094.           short     theItem;
  1095.       {
  1096.       
  1097.           Rect     itemRect;
  1098.           Handle   itemHandle;
  1099.           short    itemType;
  1100.           short    diameter;
  1101.           
  1102.           GetDItem( theDialog, 1, &itemType, &itemHandle, &itemRect );
  1103.           diameter = (itemRect.bottom - itemRect.top) / 2;
  1104.           if ( diameter < 16 )
  1105.               diameter = 16;
  1106.           PenSize( 3, 3 );
  1107.           InsetRect( &itemRect, -4, -4 );
  1108.           FrameRoundRect( &itemRect, diameter, diameter );
  1109.  
  1110.       }
  1111.       
  1112.       
  1113.       
  1114.       /* Assume myDialog has been initialized, and item #4 is the dummy
  1115.          user item for outlining the default button.  The following lines
  1116.          install the outlining procedure OutlineDefault into the user
  1117.          item, so that OutlineDefault will be called by the Dialog Manager
  1118.          each time the dialog needs to be redrawn. */
  1119.       
  1120.       GetDItem( myDialog, 4, &itemType, &itemHandle, &itemRect );
  1121.       SetDItem( myDialog, 4, itemType, OutlineDefault, &itemRect );
  1122.  
  1123.  
  1124. -----------------------------------------------------------------------------
  1125.  
  1126.  
  1127. (9) How do I go about writing serial port communications?
  1128.  
  1129.     These days, it is best to use the new Comunications Toolbox (CTB).
  1130.     By utiizing the CTB, you will be able to write your code to a single
  1131.     specification, and the code will work with all current CTB "tools" and
  1132.     all future CTB tools. The CTB tools allow programmers to extend the
  1133.     CTB's functionality. There is a tool for each facet of the communications
  1134.     puzzle: Connection Tools, Terminal Tools, and File Transfer Tools.
  1135.  
  1136.     For example, once I have written a piece of code that uses the Serial
  1137.     tool to connect me to a terminal server, combined with the VT102 Tool
  1138.     to emulate a vt102 terminal, and the XMODEM Macbinary Tool to transfer
  1139.     files, the same code will work with Apple Modem Tool, TCP/IP, AppleTalk
  1140.     ADSP, ISDN, X.25, and all future Connection Tools. Further, the terminal
  1141.     can emulate a VT320, ASCII, or other terminals. Files may be transfered
  1142.     with XMODEM, TEXT, and soon ZMODEM and Kermit protocols.
  1143.  
  1144.     The disadvantage of the CTB is that you must limit yourself to the
  1145.     specification of the Connection, Terminal, and File Transfer interfaces.
  1146.     These limitations are *rarely* a problem, but clearly something like
  1147.     a FAX interface program or real time data analyzer, would have to
  1148.     seriously consider the interfaces before committing.
  1149.  
  1150.     For most standard communications applications, such as terminal emulators,
  1151.     Bulletin Board Systems, etc., the CTB is the correct choice.
  1152.  
  1153.     You can only get the CTB development kit from APDA. It is affordable,
  1154.     somewhere just under $100. This includes working sample code.
  1155.  
  1156.  
  1157. -----------------------------------------------------------------------------
  1158.  
  1159.  
  1160. (10) How do I get the menubar to disappear and re-appear?
  1161.  
  1162.      A set of routines to do this in Pascal can be found in the Usenet
  1163.      Macintosh Programmer's Guide.  You can also ftp some sample code in C
  1164.      from skinner.cs.uoregon.edu in /pub/mac/menu-bar.c.
  1165.  
  1166.  
  1167. -----------------------------------------------------------------------------
  1168.  
  1169.  
  1170. (11) How do I write an INIT?
  1171.  
  1172.      There is a simple INIT (SetWindow INIT) with source code and
  1173.      explanations in the Usenet Macintosh Programmer's Guide.
  1174.  
  1175.  
  1176. -----------------------------------------------------------------------------
  1177.  
  1178.  
  1179. (12) How do you access the application's data fork?
  1180.  
  1181.      Call CurResFile when the application starts up.
  1182.      Call PBGetFCBInfo to convert that refNum into a vRefNum, dirID and name.
  1183.      Call HOpen with the vRefNum, dirID, and name to open up your data fork.
  1184.  
  1185.  
  1186. -----------------------------------------------------------------------------
  1187.  
  1188.  
  1189. (13) What is the fastest way to paint one pixel on the screen?
  1190.  
  1191.      Using QuickDraw, the fastest way to draw one pixel is
  1192.         MoveTo( x, y );
  1193.         Line( 0, 0 );
  1194.      making sure that the pen size is 1 by 1.  This is about twice as fast as
  1195.      setting the pen size to 0 by 1 or 1 by 0 and calling Line( 1, 0 ) or
  1196.      Line( 0, 1 ), respectively.  I'm not sure why....
  1197.    
  1198.      See below for how to draw a pixel without using QuickDraw.
  1199.  
  1200.  
  1201. -----------------------------------------------------------------------------
  1202.  
  1203.  
  1204. (14) How do you draw directly into a pixmap without using QuickDraw?
  1205.  
  1206.      As an example, here is a routine that paints a single pixel in a pixmap.
  1207.      To use this procedure, you just have to know what 'value' to pass in.
  1208.      This depends on the current bit-depth of 'thePixMap.'  The rightmost n
  1209.      bits of 'value' are used for the pixel value for depth = n.  For depths
  1210.      of eight or less, the value of each pixel is an index into a color
  1211.      table.  For depth = 16, each 16-bit pixel is interpreted as an RGB
  1212.      value, as follows:
  1213.    
  1214.          Bit: 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
  1215.        Value:  R  R  R  R  R  G  G  G  G  G  B  B  B  B  B  U
  1216.    
  1217.      where R = Red, G = Green, B = Blue, and U = Unused.  For depth = 32,
  1218.      each 32-bit pixel is interpreted as an RGB value as follows:
  1219.    
  1220.          Bit: 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
  1221.        Value:  A  A  A  A  A  A  A  A  R  R  R  R  R  R  R  R
  1222.    
  1223.          Bit: 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
  1224.        Value:  G  G  G  G  G  G  G  G  B  B  B  B  B  B  B  B
  1225.    
  1226.      where R = Red, G = Green, B = Blue, and A = Alpha.
  1227.  
  1228.  
  1229.  
  1230.      void SetPixel(
  1231.          short           x,
  1232.          short           y,
  1233.          long            value,
  1234.          PixMapHandle    thePixMap )
  1235.      {
  1236.  
  1237.          unsigned long   rowBytes;
  1238.          unsigned char   mask;
  1239.          unsigned char   shiftBits;
  1240.          unsigned char   *thePixel;
  1241.          unsigned char   pixelDepth;
  1242.          char            mode = true32b;
  1243.          Boolean         swapMode;
  1244.     
  1245.          swapMode = PixMap32Bit( thePixMap );
  1246.  
  1247.          LockPixels( thePixMap );
  1248.  
  1249.          rowBytes = (unsigned long) ((*thePixMap)->rowBytes & 0x3fff);
  1250.          thePixel = (unsigned char *) (*thePixMap)->baseAddr;
  1251.     
  1252.          pixelDepth = (*thePixMap)->pixelSize;
  1253.  
  1254.          switch ( pixelDepth ) {
  1255.     
  1256.              case 1:
  1257.              case 2:
  1258.              case 4:
  1259.              case 8:
  1260.  
  1261.                  thePixel += (rowBytes * y) +
  1262.                              (((unsigned long) pixelDepth * x) / 8L);
  1263.  
  1264.                  shiftBits = ((8 - pixelDepth) - ((x * pixelDepth) % 8));
  1265.  
  1266.                  mask = (unsigned char) ((1 << pixelDepth) - 1) << shiftBits;
  1267.  
  1268.                  if ( swapMode ) {
  1269.                      SwapMMUMode( &mode );
  1270.                  }
  1271.             
  1272.                  *thePixel &= ~mask;
  1273.                  *thePixel |= (unsigned char) value << shiftBits;
  1274.             
  1275.                  break;
  1276.            
  1277.            
  1278.              case 16:
  1279.  
  1280.                  thePixel += (rowBytes * y) + (2L * x);
  1281.  
  1282.                  if ( swapMode ) {
  1283.                      SwapMMUMode( &mode );
  1284.                  }
  1285.             
  1286.                  *((unsigned short *)thePixel) = (unsigned short) value;
  1287.                
  1288.                  break;
  1289.         
  1290.         
  1291.              case 24:    /* untested */
  1292.            
  1293.                  thePixel += (rowBytes * y) + (3L * x);
  1294.             
  1295.                  if ( swapMode ) {
  1296.                      SwapMMUMode( &mode );
  1297.                  }
  1298.             
  1299.                  *thePixel = (unsigned char) (value >> 16);
  1300.                  *((unsigned short *)(thePixel+1)) = (unsigned short) value;
  1301.             
  1302.                  break;
  1303.         
  1304.         
  1305.              case 32:
  1306.            
  1307.                  thePixel += (rowBytes * y) + (4L * x);
  1308.             
  1309.                  if ( swapMode ) {
  1310.                      SwapMMUMode( &mode );
  1311.                  }
  1312.             
  1313.                  *((unsigned long *)thePixel) = value;
  1314.             
  1315.                  break;
  1316.         
  1317.         
  1318.              default:
  1319.                  break;
  1320.     
  1321.          }
  1322.  
  1323.          if ( swapMode ) {
  1324.              SwapMMUMode( &mode );
  1325.          }
  1326.  
  1327.          UnlockPixels( thePixMap );
  1328.  
  1329.      }
  1330.  
  1331.  
  1332. -----------------------------------------------------------------------------
  1333.  
  1334.  
  1335. (15) How do you draw directly onto the screen without using QuickDraw?
  1336.  
  1337.      Get the pixmap for the monitor that you want to draw on, and send it to
  1338.      the above procedure.  For example, to draw a red dot at position 10,10
  1339.      on the main screen (if the main screen is in 32-bit mode):
  1340.  
  1341.         GDHandle   theDevice;
  1342.       
  1343.         theDevice = GetMainDevice();
  1344.       
  1345.         SetPixel( x, y, 0x00FF0000, (*theDevice)->gdPMap );
  1346.    
  1347.      If you are drawing directly to the screen, you should always wrap your
  1348.      drawing with calls to ShieldCursor and ShowCursor.  Some monitors such
  1349.      as the Radius Pivot series keep a virtual screen, and they don't update
  1350.      the real screen unless they have to.  When you write directly to the
  1351.      screen, you're actually writing to the virtual screen, and your drawing
  1352.      won't show up on the real screen until the system has some other reason
  1353.      to update the monitor.  Calling ShieldCursor each time you draw will
  1354.      force these systems to update the real screen when you expect them to.
  1355.  
  1356.  
  1357. -----------------------------------------------------------------------------
  1358.  
  1359.  
  1360. (16) How do you register signatures and file types with Apple?
  1361.  
  1362.      Registering a signature and file type is free, and you don't have to be
  1363.      an Apple Partner or Associate.  You can ftp the registration form from
  1364.      ftp.apple.com; it's available as
  1365.          /dts/mac/tools/creator-file-type-form.txt.
  1366.  
  1367.  
  1368. -----------------------------------------------------------------------------
  1369.  
  1370.  
  1371. (17) What RGB value does the system use for dimmed buttons, menus and
  1372.      window titles?
  1373.  
  1374.      The gray color does not have a fixed RGB value.  It is a weighted
  1375.      average of the foreground and background colors.  To obtain the
  1376.      appropriate 'gray' color for a given foreground and background color,
  1377.      the Palette Manager routine GetGray can be used:
  1378.  
  1379.      pascal Boolean GetGray( GDHandle device, const RGBColor *backGround,
  1380.                              RGBColor *foreGround )
  1381.        = {0x303C,0x1219,0xAAA2};
  1382.    
  1383.      If at least one gray or intermediate color is available, GetGray stores
  1384.      the color in foreGround and returns true.  If no gray is available, or,
  1385.      if you supplied two colors, no third distinguishable color is available,
  1386.      the foreGround parameter is unchanged and the function returns false.
  1387.      
  1388.      GetGray is not available in older versions of the system.  Use Gestalt
  1389.      to determine whether it is available.
  1390.  
  1391.  
  1392. -----------------------------------------------------------------------------
  1393.  
  1394.  
  1395. (18) What's the difference between the resource ID of a 'MENU' resource and
  1396.      the menuID field of that resource?
  1397.  
  1398.      The resource ID of a 'MENU' resource is just the resource ID - it has no
  1399.      hidden meaning.  What is normally expected by beginning programmers is
  1400.      that the number that MenuSelect and MenuKey return is the resource ID of
  1401.      the menu.  In fact, the number returned is the value of the menuID field
  1402.      of the menu, and has no relation to the resource ID of the menu.  You
  1403.      can set the menuID to any number you want, but by convention it is
  1404.      expected to be the same as the resource ID of the menu.  (You can change
  1405.      this value in ResEdit by opening the menu you wish to change, and
  1406.      selecting 'Edit Menu & MDEF ID...' from the MENU menu.)
  1407.  
  1408.  
  1409. -----------------------------------------------------------------------------
  1410.  
  1411.  
  1412. (19) When should I call MoveHHi?
  1413.  
  1414.      MoveHHi is an expensive operation; calling it when you don't need to can
  1415.      significantly slow down your program.  Additionally, over-calling of
  1416.      MoveHHi can fragment the top of your heap.  Call MoveHHi before locking
  1417.      a handle that is followed by some memory allocation.  To effieciently
  1418.      move a handle high in the heap and then lock it, you might want to call
  1419.      HLockHi, a call new with MPW 3.2 and THINK C 5.0 (probably THINK Pascal
  1420.      4.0 as well).
  1421.  
  1422.  
  1423.  
  1424. *****************************************************************************
  1425.  
  1426.  
  1427. Eternal Debates
  1428.  
  1429.    These questions have no final answers.  They pop up every few months and
  1430.    waste a tremendous amount of valuable network resources on discussions
  1431.    that will never be resolved.  Most people would be happy if they were
  1432.    never discussed again in this newsgroup.
  1433.  
  1434.  
  1435. Q: Why doesn't the Mac do preemptive multitasking?
  1436.  
  1437. A: Pro-preemptives claim the current scheme is too vulnerable to ill-behaved
  1438.    applications and too much trouble for application writers.  Anti-
  1439.    preemptives claim that preemptive multitasking would reduce interactive
  1440.    response, and that the current cooperative system works well.
  1441.  
  1442.  
  1443.  
  1444.  
  1445. *****************************************************************************
  1446.  
  1447.  
  1448. Credits / Acknowledgements
  1449.  
  1450.  
  1451. Many thanks to Ben Haller, who started this whole thing, and did quite a lot
  1452. of work on this posting before handing it off to me.
  1453.  
  1454. Thanks to these people for proofreading this list during its development:
  1455.     Ben Haller
  1456.     Wally Wedel
  1457.     John B. Matthews
  1458.     Patrick Beard
  1459.     Steve Zellers
  1460.  
  1461. Thanks to Chris Webster for the one-liners.
  1462.  
  1463. Thanks to Peter Lewis for the answers to the following specific questions:
  1464.     How do you get a full pathname?
  1465.     How could anyone love the File Manager?
  1466.     When do you put an ellipsis on the end of a menu item?
  1467.     How do you set the SFGet/PutFile directory?
  1468.  
  1469. Thanks to Greg Ferrar for the review on TMON Pro.
  1470.  
  1471. Thanks to John Rinaldo for the review on Jasik's Debugger.
  1472.  
  1473. And thanks to everyone who has offered suggestions or constructive
  1474. criticism....  Keep those comments coming!
  1475.  
  1476.  
  1477.  
  1478.  
  1479.