MacOS


Here is a program for the MacOS.  It is not the shortest by any means
whatsoever -- I do a lot of unnecessary stuff because I basically copied
it from apple sample code.  To repeat, you could just put a repeat loop
around the whole thing.  Better though would be to do an alert of some
kind.  But you need a rez compiler for that, so I didn't do it.

Ricky Morse

-

program macosHelloWorld;

var
    theWindow: WindowPtr;
    wBoundsRect: rect;
    gDone: boolean;
    myEvent: EventRecord;
    gotEvent: Boolean;                    {is returned event for me?}


procedure initToolbox;
    begin
        InitGraf(@thePort);               {initialize QuickDraw}
        InitFonts;                        {initialize Font Manager}
        InitWindows;                      {initialize Window Manager}
        TEInit;                           {initialize TextEdit}

        FlushEvents(everyEvent, 0);       {clear event queue}
        InitCursor;                       {initialize cursor to arrow}
    end; {initToolbox}


procedure drawTheText (w: WindowPtr);     {Draw the text on the window}
    const
        s = 'Hello, World!';
    var
        textLength, textHeight: integer;
        x, y: integer;
        info: fontInfo;
    begin
        setPort(w);                       {sets up the drawing port}
        TextFont(applFont);               {geneva}
        TextFace([]);                     {plain text}
        TextSize(72);                     {72 pts}

        GetFontInfo(info);                {get info on font height}

        textLength := StringWidth(s);     {save width and height}
        textHeight := info.ascent + info.leading;

                                          {center text on screen}

        x := (w^.portRect.right) - (w^.portRect.left);
        x := round(x / 2);

        x := round(x - (textLength / 2));

        y := (w^.portRect.bottom) - (w^.portRect.top);
        y := round(y / 2);

        y := round(y - (textHeight / 2));

        MoveTo(x, y);                     {draw the stuff}
        DrawString(s);

    end; {drawTheText}

begin {macosHelloWorld}
    initToolbox;
    gDone := false;

    with screenBits.bounds do             {set the window size based on
the screen size}
        setRect(wBoundsRect, left + 4, top + 40, right - 4, bottom - 4);
                                          {create a new window}
    theWindow := newWindow(nil, wBoundsRect, '', true, documentProc,
pointer(-1), false, 0);

    drawTheText(theWindow);

    repeat                                {wait until the user clicks
the mouse}
        gotEvent := WaitNextEvent(everyEvent, myEvent, 15, nil);
        if gotEvent then
            case myEvent.what of
                mouseDown: 
                    gDone := true;
                otherwise
                    ;
            end; {case}
    until gDone;

    DisposeWindow(theWindow);             {clear up window memory}

end. {macosHelloWorld}


submitted by: rem14@cornell.edu (Richard Morse)