Important: The information in this document is obsolete and should not be used for new development.
NewWindow
Use theNewWindowfunction to create a new window with the characteristics specified by a list of parameters when Color QuickDraw is not available. TheNewWindowfunction takes the same parameters asNewCWindowand, likeNewCWindow, returns aWindowPtras its function result. The only difference is thatNewWindowcreates a window in a monochrome graphics port, not a color graphics port. The window record and graphics port record that describe monochrome and color graphics ports are the same size and can be used interchangeably in most Window Manager routines.
FUNCTION NewWindow (wStorage: Ptr; boundsRect: Rect; title: Str255; visible: Boolean; theProc: Integer; behind: WindowPtr; goAwayFlag: Boolean; refCon: LongInt): WindowPtr;
- wStorage
- A pointer to the window record. If you specify
NILas the value ofwStorage,NewWindowallocates the window record as a nonrelocatable object in the heap. You can reduce the chances of heap fragmentation by allocating the storage from a block of memory reserved for this purpose by your application and passing a pointer to it in thewStorageparameter.- boundsRect
- A rectangle, in global coordinates, specifying the window's initial size and location. This parameter becomes the port rectangle of the window's graphics port. For the standard window types,
boundsRectdefines
the content region of the window. TheNewWindowfunction places
the origin of the local coordinate system at the upper-left corner of the port rectangle.- Note
- The
NewWindowfunction actually calls the QuickDraw procedureOpenPortto create the graphics port. The bitmap, pen pattern, and
other characteristics of the window's graphics port are the same as
the default values set byOpenPort, except for the character font,
which is set to the application font instead of the system font. The coordinates of the graphics port's port boundaries and visible region
are changed along with its port rectangle.![]()
title- A string that specifies the window's title.
- If the title is too long to fit in the title bar, the title is truncated. If the window has a close box, characters at the end of the title are truncated; if there's no close box, the title is centered and truncated at both ends.
- To suppress the title in a window with a title bar, pass an empty string, not
NIL.- visible
- A Boolean value indicating visibility status:
TRUEmeans that the Window Manager displays the window;FALSEmeans it does not.- If the value of the
visibleparameter isTRUE, the Window Manager draws a new window as soon as the window exists. The Window Manager first calls the window definition function to draw the window frame. If the value of thegoAwayFlagparameter (described below) is alsoTRUEand the window is frontmost (that is, if the value of thebehindparameter isPointer(-1)), the Window Manager instructs the window definition function to draw a close box in the window frame. After drawing the frame, the Window Manager generates an update event to trigger your application's drawing of the content region.- When you create a window, you typically specify
FALSEas the value of thevisibleparameter. When you're ready to display the window, you call theShowWindowprocedure, described on page 4-80.- theProc
The window's definition ID, which specifies both the window definition function and the variation code for that definition function.- The Window Manager supports nine standard window types, which are handled by two window definition functions. You can create windows of the standard types by specifying one of the type constants:
CONST documentProc = 0; {standard document } { window, no zoom box} dBoxProc = 1; {alert box or modal } { dialog box} plainDBox = 2; {plain box} altDBoxProc = 3; {plain box with shadow} noGrowDocProc = 4; {movable window, } { no size box or zoom box} movableDBoxProc = 5; {movable modal dialog box} zoomDocProc = 8; {standard document window} zoomNoGrow = 12; {zoomable, nonresizable } { window} rDocProc = 16; {rounded-corner window}
- You can control the diameter of curvature of rounded-corner windows by adding an integer to the
rDocProcconstant, as described in "The Window Resource" beginning on page 4-116.behind- A pointer to the window that appears immediately in front of the new window on the desktop.
- To place a new window in front of all other windows on the desktop, specify a value of
Pointer(-1). When you place a new window in front of all others,NewWindowremoves highlighting from the previously active window, highlights the newly created window, and generates activate events that trigger your application's updating of both windows. Note that if you create an invisible window in front of all others on the desktop, the user sees no active window until you make the new window visible (or make another window active).- To place a new window behind all other windows, specify a value of
NIL.- goAwayFlag
- A Boolean value that determines whether or not the window has a close box. If the value of
goAwayFlagisTRUEand the window type supports a close box, the Window Manager draws a close box in the title bar and recognizes mouse clicks in the close region; if the value ofgoAwayFlagisFALSEor the window type does not support a close box, it does not.- refCon
- The window's reference constant, set and used only by your application. (See "Managing Multiple Windows" beginning on page 4-23 for some suggested ways to use the
refConparameter.)DESCRIPTION
TheNewWindowfunction creates a window as specified by its parameters, adds it to the window list, and returns a pointer to the newly created window record. You can use the returned window pointer to refer to this window in most Window Manager routines. IfNewWindowis unable to read the window definition function from the resource file, it returnsNIL.If the window's definition function is not already in memory,
NewWindowreads it into memory and stores a handle to it in the window record. It allocates space for the structure and content regions of the window and asks the window definition function to calculate those regions.Storing the characteristics of your windows as resources, especially window titles and window items, makes your application easier to localize.
SPECIAL CONSIDERATIONS
If you let the Window Manager create the window record in your application's heap, call theDisposeWindowprocedure to close the window and dispose of its window record. If you allocated the memory for the window record yourself and passed a pointer toNewCWindow, use theCloseWindowprocedure to close the window and theDisposePtrprocedure, documented in Inside Macintosh: Memory, to dispose of the window record.SEE ALSO
For the procedures for closing a window and removing the structures from memory, see the descriptions of theDisposeWindowprocedure on page 4-97, theCloseWindowprocedure on page 4-96, and theDisposePtrprocedure in Inside Macintosh: Memory.