home *** CD-ROM | disk | FTP | other *** search
- /* *****************************************************************************
- FILE: Hello.c
-
- DESCRIPTION: Hello world source file.
- Developed for our MacUser readers.
-
- AUTHOR: Kurt W.G. Matthies
-
- Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
-
- Revision History:
- ==========================================================
- 3/1/90 - MacUser Release
- ==========================================================
-
-
- Installation instructions:
- --------------------------
-
- This code was developed in THINK C 3.0. You can't open
- the project file with Lightspeed version 1 or 2 because of
- the newer format. All you need to do is 1) Create a new project
- file named Hello Proj, and 2) Add Hello.c and MacTraps to the
- file.
-
- ***************************************************************************** */
-
- #define kHelloString "\pHello, world!"
-
- /* ------------------------- Local Prototypes ---------------------------------- */
- void main ( void );
- void initTheMac ( void );
- WindowPtr initWindow ( void );
- void sayHello ( WindowPtr );
- void getMouseDown ( void );
-
- /* -----------------------------------------------------------------------------
- main - program entry point
- -------------------------------------------------------------------------------- */
- void
- main ()
- {
- WindowPtr theWindow;
-
- initTheMac ();
-
- if (theWindow = initWindow ())
- {
- sayHello (theWindow);
-
- getMouseDown ();
-
- DisposeWindow (theWindow);
- }
-
- ExitToShell ();
-
- } /* main */
-
- /* -----------------------------------------------------------------------------
- initTheMac - initialize the necessary managers for this to be a
- stand-alone application
- -------------------------------------------------------------------------------- */
- void
- initTheMac ()
- {
- InitGraf (&thePort);
- InitWindows();
- InitFonts ();
- InitCursor ();
- }
-
- /* -----------------------------------------------------------------------------
- initWindow - initialize a window for this application. Activate the
- window and return the pointer to the window record.
- return 0L on fail
- -------------------------------------------------------------------------------- */
- WindowPtr
- initWindow ()
- {
- WindowPtr w;
- Rect windowRect;
-
- SetRect (&windowRect, 40, 40, 340, 240);
-
- if (w = NewWindow (0L, &windowRect,"\p", true, dBoxProc, -1L, false, 0L))
- SetPort (w);
-
- return (w);
-
- } /* initWindow */
-
- /* -----------------------------------------------------------------------------
- sayHello - print the hello world string in the center of theWindow
- -------------------------------------------------------------------------------- */
- void
- sayHello (theWindow)
- WindowPtr theWindow;
- {
- Rect windowRect;
- Point penLoc;
-
- /* get the center of the window */
- windowRect = theWindow->portRect;
- penLoc.h = (windowRect.left + windowRect.right) / 2;
- penLoc.v = (windowRect.top + windowRect.bottom) / 2;
-
- /* offset the pen's horizontal location by half the string width */
- penLoc.h -= StringWidth (kHelloString) / 2;
-
- MoveTo (penLoc.h, penLoc.v);
-
- DrawString (kHelloString);
-
- } /* sayHello */
-
- /* -----------------------------------------------------------------------------
- getMouseDown - wait for a mouse down event
- -------------------------------------------------------------------------------- */
- void
- getMouseDown ()
- {
- EventRecord eventRec;
-
- FlushEvents (everyEvent, 0); /* clear the event queue */
-
- while (!GetNextEvent (mDownMask, &eventRec)); /* idle until a mouse down */
- }
-
- /* =============================== EOF =======================================
- Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
- ================================================================================ */