Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: How do I make the Menu Bar disappear Summary: Don't use my previous posting. Message-ID: <12880@dartvax.Dartmouth.EDU> Date: 4 Apr 89 18:31:32 GMT References: <28192@apple.Apple.COM> <12865@dartvax.Dartmouth.EDU> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 164 In article <12865@dartvax.Dartmouth.EDU> earleh@eleazar.dartmouth.edu (Earle R. Horton) writes: >In article <28192@apple.Apple.COM> kmcentee@Apple.COM (Kevin McEntee) writes: >> >>Does anyone know of a quick and dirty way that a multifinder application can >>make the menu bar disappear? Like in HyperCard? >> >> > You mean like this? ... The code I posted yesterday would cause problems in the unlikely event that your program would crash while the Menu Bar was hidden. Specifically, it would replace GrayRgn with a handle to a Region in the application heap, and save the real GrayRgn Handle for restoration later when you restored the Menu Bar. If your program crashed, and the Menu Bar was hidden, then GrayRgn was left pointing to a Region in a defunct application heap, which could cause all sorts of problems for applications which were still running. This version does not change the Handle, but rather modifies the contents of GrayRgn. If you crash with the Menu Bar hidden, GrayRgn is left pointing to a valid area of storage, at least. There are still problems since the Menu Bar can be left hidden, but these are slightly less severe than leaving a dangling Handle in the system heap. Earle ----------------------cut here---------------------- { This unit provides the ability to hide the Menu Bar, and to show it. When the Menu Bar is hidden, windows may be placed in the area normally used for the Menu Bar. Usage: PROCEDURE MBar_Init: Used to initialize global variables used here. Call once at beginning of application code. PROCEDURE MBar_be_Gone; Hides the Menu Bar. PROCEDURE MBar_Restore; Shows the Menu Bar. Call this whenever you are going to be put into the background. Call before Exit. The procedures in this unit will probably break under some future release of the Macintosh Operating System, because they manipulate the GrayRgn. They do work under MultiFinder 6.1a2. The most serious warning I can give concerning use of these routines is that you must never allow your application to be placed into the background with the Menu Bar hidden. Possible compatibility problems: Modifies lowmem MBarHeight Modifies contents of GrayRgn This file is part of Earle R. Horton's private source code library. Earle R. Horton assumes no responsibility for any damages arising out of use of this source code for any purpose. Earle R. Horton places no restrictions on use of all or any part of this source code, except that this paragraph may not be altered or removed. Original Language: MPW Pascal, v. 2.0.2 Origination Date: March 20, 1989 Modifications: April 4, 1989 ERH First version changed lowmem GrayRgn to point to a Region in the application heap while the Menu Bar was hidden. This version copies the new Region to GrayRgn. If the application crashes with the Menu Bar hidden, GrayRgn no longer points to part of the defunct application heap. There are still problems, however, because the Menu Bar is left hidden and other applications cannot access it. } UNIT MenuBar; INTERFACE USES {$Load PasDump.dump} Memtypes, Quickdraw, OSIntf, Script, ToolIntf; PROCEDURE MBar_be_Gone; PROCEDURE MBar_Restore; PROCEDURE MBar_Init; PROCEDURE SetMBarHeight(newheight:integer); INLINE smPopStack2Word,smMBarHeight; { move.w (a7)+,$0BAA } VAR Real_MBar_Height: integer; { Copy of lowmem MBarHeight } Save_Region: RgnHandle; { Copy of GrayRgn } Hidden_Flag: Boolean; { State info } MBar_Rect: Rect; { Rect in which MBar is drawn } IMPLEMENTATION PROCEDURE MBar_Init; BEGIN Hidden_FLag := false; Real_MBar_Height := GetMBarHeight; SetRect(MBar_Rect, screenBits.bounds.left, screenBits.bounds.top, screenBits.bounds.right, screenBits.bounds.top + Real_MBar_Height); END; { Make the Menu Bar go away under MultiFinder or UniFinder. Since this procedure manipulates the Gray Region, future compatibility is unknown. } PROCEDURE MBar_be_Gone; VAR MBar_Region: RgnHandle; theWindow: WindowPeek; BEGIN IF not Hidden_Flag THEN BEGIN Hidden_Flag := true; { Get some Regions to work with. } Save_Region := NewRgn; MBar_Region := NewRgn; { Set the Menu Bar height to zero. } SetMBarHeight(0); { Save the old GrayRgn. } CopyRgn(GetGrayRgn,Save_Region); { Fix up GrayRgn to cover the old GrayRgn plus the Menu Bar Rect. } RectRgn(MBar_Region,MBar_Rect); UnionRgn(GetGrayRgn,MBar_Region,GetGrayRgn); { Paint and fix up visRgn for any windows with exposed area. } theWindow := WindowPeek(FrontWindow); PaintOne(theWindow,MBar_Region); PaintBehind(theWindow,MBar_Region); CalcVis(theWindow); CalcVisBehind(theWindow,MBar_Region); DisposeRgn(MBar_Region); { Clean up, leave. } END; END; { Restore the Menu Bar and GrayRgn to normality. Call when app is put into background. } PROCEDURE MBar_Restore; VAR theWindow: WindowPeek; BEGIN IF Hidden_Flag THEN BEGIN Hidden_Flag := false; { Restore to original } CopyRgn(Save_Region,GetGrayRgn); { Restore Menu Bar height } SetMBarHeight(Real_MBar_Height); { Fix up any covered windows } RectRgn(Save_Region,MBar_Rect); theWindow := WindowPeek(FrontWindow); CalcVis(theWindow); CalcVisBehind(theWindow,Save_Region); DisposeRgn(Save_Region); { Draw the Menu, get out of here } HiliteMenu(0); DrawMenuBar; END; END; END.