home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacUserProj / MacUser Projects / Hello World / Hello.c < prev   
Encoding:
C/C++ Source or Header  |  1990-02-06  |  3.7 KB  |  132 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             Hello.c
  3.     
  4.     DESCRIPTION:     Hello world source file.
  5.                     Developed for our MacUser readers.
  6.  
  7.     AUTHOR:            Kurt W.G. Matthies
  8.         
  9.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     3/1/90    -    MacUser Release
  14.     ==========================================================
  15.     
  16.  
  17.     Installation instructions: 
  18.     --------------------------
  19.     
  20.     This code was developed in THINK C 3.0. You can't open
  21.     the project file with Lightspeed version 1 or 2 because of 
  22.     the newer format. All you need to do is 1) Create a new project
  23.     file named Hello Proj, and 2) Add Hello.c and MacTraps to the
  24.     file. 
  25.  
  26.    ***************************************************************************** */
  27.  
  28. #define        kHelloString        "\pHello, world!"
  29.  
  30. /* ------------------------- Local Prototypes ---------------------------------- */
  31. void            main            ( void );
  32. void            initTheMac        ( void );
  33. WindowPtr        initWindow        ( void );
  34. void            sayHello        ( WindowPtr );
  35. void            getMouseDown    ( void );
  36.  
  37. /* -----------------------------------------------------------------------------
  38.     main -    program entry point
  39. -------------------------------------------------------------------------------- */
  40. void
  41. main ()
  42. {
  43.     WindowPtr        theWindow;
  44.     
  45.     initTheMac ();
  46.     
  47.     if (theWindow = initWindow ())
  48.     {
  49.         sayHello (theWindow);
  50.         
  51.         getMouseDown ();
  52.         
  53.         DisposeWindow (theWindow);
  54.     }
  55.     
  56.     ExitToShell ();
  57.  
  58. } /* main */
  59.  
  60. /* -----------------------------------------------------------------------------
  61.     initTheMac -    initialize the necessary managers for this to be a 
  62.                     stand-alone application
  63. -------------------------------------------------------------------------------- */
  64. void
  65. initTheMac ()
  66. {
  67.     InitGraf (&thePort);
  68.     InitWindows();
  69.     InitFonts ();
  70.     InitCursor ();
  71. }
  72.     
  73. /* -----------------------------------------------------------------------------
  74.     initWindow -    initialize a window for this application. Activate the 
  75.                     window and return the pointer to the window record. 
  76.                     return 0L on fail
  77. -------------------------------------------------------------------------------- */
  78. WindowPtr
  79. initWindow ()
  80. {
  81.     WindowPtr    w;
  82.     Rect        windowRect;
  83.     
  84.     SetRect (&windowRect, 40, 40, 340, 240);
  85.     
  86.     if (w = NewWindow (0L, &windowRect,"\p", true, dBoxProc, -1L, false, 0L))
  87.         SetPort (w);
  88.  
  89.     return (w);
  90.     
  91. } /* initWindow */
  92.  
  93. /* -----------------------------------------------------------------------------
  94.     sayHello -    print the hello world string in the center of theWindow
  95. -------------------------------------------------------------------------------- */
  96. void
  97. sayHello (theWindow)
  98.     WindowPtr        theWindow;
  99. {
  100.     Rect            windowRect;
  101.     Point            penLoc;
  102.     
  103.     /* get the center of the window */
  104.     windowRect = theWindow->portRect;
  105.     penLoc.h = (windowRect.left + windowRect.right) / 2;
  106.     penLoc.v = (windowRect.top + windowRect.bottom) / 2;
  107.     
  108.     /* offset the pen's horizontal location by half the string width */
  109.     penLoc.h -= StringWidth (kHelloString) / 2;
  110.     
  111.     MoveTo (penLoc.h, penLoc.v);
  112.     
  113.     DrawString (kHelloString);
  114.     
  115. } /* sayHello */
  116.  
  117. /* -----------------------------------------------------------------------------
  118.     getMouseDown -    wait for a mouse down event 
  119. -------------------------------------------------------------------------------- */
  120. void
  121. getMouseDown ()
  122. {
  123.     EventRecord        eventRec;
  124.     
  125.     FlushEvents (everyEvent, 0);                    /* clear the event queue */
  126.     
  127.     while (!GetNextEvent (mDownMask, &eventRec));    /* idle until a mouse down */
  128. }
  129.  
  130. /* ===============================  EOF  =======================================
  131.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  132. ================================================================================ */