Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
HideMenuBar.c
/* |
File: HideMenuBar.c |
Contains: This snippet shows how to hide the menu bar by simply |
creating a window with a visRgn that includes the |
entire main screen's gray region and its menu bar. |
Written by: Edgar Lee |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/9/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
HideMenuBar() Is now included in the OS in |
MenusLib |
*/ |
#include <Quickdraw.h> |
#include <Dialogs.h> |
#include <Fonts.h> |
#include <Processes.h> |
/* Global Variable Definitions */ |
WindowPtr gWindow; |
void initMac(); |
//void HideMenuBar(); |
void HideIt(); |
void drawWindow(); |
void doEventLoop(); |
void main(void) |
{ |
initMac(); |
HideMenuBar(); |
doEventLoop(); |
} |
void initMac() |
{ |
MaxApplZone(); |
InitGraf( &qd.thePort ); |
InitFonts(); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs( nil ); |
InitCursor(); |
FlushEvents( 0, everyEvent ); |
} |
/*void HideMenuBar() |
{ |
Rect rect; |
gWindow = NewCWindow( 0L, &rect, "\p", false, plainDBox, |
(WindowPtr)-1L, true, 0L ); |
MoveWindow( gWindow, qd.screenBits.bounds.left, qd.screenBits.bounds.top, true ); |
SizeWindow( gWindow, qd.screenBits.bounds.right - qd.screenBits.bounds.left, |
qd.screenBits.bounds.bottom - qd.screenBits.bounds.top, false ); |
SetPort( gWindow ); |
ShowWindow( gWindow ); |
TextMode( kFontIDGeneva ); |
TextSize( 9 ); |
TextMode( srcXor ); |
}*/ |
void HideIt() |
{ |
/****************************************************/ |
/* Set the window's visRgn to include the menu bar. */ |
/****************************************************/ |
RectRgn( (*gWindow).visRgn, &qd.screenBits.bounds ); |
InvalRect( &qd.screenBits.bounds ); |
/*************************************************/ |
/* Set the global MBarHeight to 0 to prevent any */ |
/* other apps from writing to the menu bar. */ |
/*************************************************/ |
*((short *)0xbaa) = 0; |
} |
void drawWindow() |
{ |
ForeColor( redColor ); |
PaintRect( &qd.screenBits.bounds ); |
MoveTo( 15, 15 ); |
DrawString( "\pPress any key to quit." ); |
} |
void doEventLoop() |
{ |
EventRecord event; |
WindowPtr window; |
short clickArea; |
Rect screenRect; |
for (;;) |
{ |
if (WaitNextEvent( everyEvent, &event, 0, nil )) |
{ |
if (event.what == mouseDown) |
{ |
clickArea = FindWindow( event.where, &window ); |
if (clickArea == inDrag) |
{ |
screenRect = (**GetGrayRgn()).rgnBBox; |
DragWindow( window, event.where, &screenRect ); |
} |
else if (clickArea == inContent) |
{ |
if (window != FrontWindow()) |
SelectWindow( window ); |
} |
else if (clickArea == inGoAway) |
if (TrackGoAway( window, event.where )) |
return; |
} |
else if (event.what == keyDown || event.what == autoKey) |
ExitToShell(); |
else if (event.what == updateEvt) |
{ |
window = (WindowPtr)event.message; |
SetPort( window ); |
BeginUpdate( window ); |
drawWindow(); |
EndUpdate( window ); |
} |
else if (event.what == activateEvt) |
{ |
HideIt(); |
} |
} |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-30