Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Macintosh Toolbox Essentials /
Chapter 4 - Window Manager / Using the Window Manager


Drawing the Window Contents

Your application and the Window Manager work together to display windows on the screen. Once you have created a window and made it visible, the Window Manager automatically draws the window frame in the appropriate location. As the user makes changes to the desktop, moving and resizing different windows, the Window Manager alters the window frames as necessary. The window frame includes the window outline, the title bar, and the close and zoom boxes.

Your application is responsible for drawing the window's content region. It typically uses the Control Manager to draw the window controls, uses the Window Manager to draw the size box, and draws the user data itself. The sample code in this chapter uses the simple model of a content region that contains only controls, the size box, and a TextEdit record. (See Inside Macintosh: Text for a description of TextEdit.)

Listing 4-8 illustrates an application-defined procedure that draws the content region of a window.

Listing 4-8 Drawing a window

PROCEDURE MyDrawWindow (window: WindowPtr);
VAR
   myData: MyDocRecHnd;
BEGIN
   SetPort(window);
   myData := MyDocRecHnd(GetWRefCon(window));
   HLock(Handle(myData));
   WITH window^ DO
   BEGIN
      EraseRect(portRect);    {erase content area}
      UpdateControls(window, visRgn);  {draw window controls}
      DrawGrowIcon(window);   {draw size box}
      {update window contents as appropriate to your }
      { application (in this case use TextEdit)}
      TEUpdate(portRect, myData^^.editRec);
   END;
   HUnLock(Handle(myData));
END;
The MyDrawWindow procedure first sets the current port to the window's port and gets a handle to the window's document record. Using the data in the document record, the procedure first erases the content region, draws the controls, and draws the size box. Finally, it draws the user's data, in this case the contents of a TextEdit edit record.

If your application creates a window that contains a static display, you can let the Window Manager take care of drawing and updating the content region by placing a handle to a picture in the windowPic field of the window record. See the description
of the SetWindowPic procedure on page 4-110.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996