home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Toolbox / HideMenuBar / Source / HideMenuBar.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  3.4 KB  |  155 lines  |  [TEXT/CWIE]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    HideMenuBar                                                */
  4. /*                                                                            */
  5. /*    Description:    This snippet shows how to hide the menu bar by simply    */
  6. /*                    creating a window with a visRgn that includes the        */
  7. /*                    entire main screen's gray region and its menu bar.        */
  8. /*                                                                            */
  9. /*    Files:            HideMenuBar.π                                            */
  10. /*                    HideMenuBar.c                                            */
  11. /*                                                                            */
  12. /*    Programmer:        Edgar Lee                                                */
  13. /*    Organization:    Apple Computer, Inc.                                    */
  14. /*    Department:        Developer Technical Support, DTS                        */
  15. /*    Language:        C (Think C version 5.0.2)                                */
  16. /*    Date Created:    09-22-92                                                */
  17. /*                                                                            */
  18. /****************************************************************************/
  19.  
  20. //updates 8/96: Prefix.h added as prefix file for 68K and PPC MC projects;
  21. //old routine names changed
  22.  
  23. #include <Quickdraw.h>
  24. #include <Dialogs.h>
  25. #include <Fonts.h>
  26. #include <Processes.h>
  27.  
  28.  
  29. /* Global Variable Definitions */
  30.  
  31. WindowPtr    gWindow;
  32.  
  33. void initMac();
  34.  
  35. void HideMenuBar();
  36. void HideIt();
  37. void drawWindow();
  38. void doEventLoop();
  39.  
  40.  
  41. void main(void)
  42. {
  43.     initMac();
  44.     
  45.     HideMenuBar();
  46.     
  47.     doEventLoop();
  48. }
  49.  
  50. void initMac()
  51. {
  52.     MaxApplZone();
  53.  
  54.     InitGraf( &qd.thePort );
  55.     InitFonts();
  56.     InitWindows();
  57.     InitMenus();
  58.     TEInit();
  59.     InitDialogs( nil );
  60.     InitCursor();
  61.     FlushEvents( 0, everyEvent );
  62. }
  63.  
  64. void HideMenuBar()
  65. {
  66.     Rect    rect;
  67.     
  68.     gWindow = NewCWindow( 0L, &rect, "\p", false, plainDBox,
  69.                             (WindowPtr)-1L, true, 0L );                        
  70.     
  71.     MoveWindow( gWindow, qd.screenBits.bounds.left, qd.screenBits.bounds.top, true );
  72.     SizeWindow( gWindow, qd.screenBits.bounds.right - qd.screenBits.bounds.left,
  73.                         qd.screenBits.bounds.bottom - qd.screenBits.bounds.top, false );
  74.     
  75.     SetPort( gWindow );
  76.     ShowWindow( gWindow );
  77.     
  78.     TextMode( geneva );
  79.     TextSize( 9 );
  80.     TextMode( srcXor );
  81. }
  82.  
  83. void HideIt()
  84. {    
  85.     /****************************************************/
  86.     /* Set the window's visRgn to include the menu bar. */
  87.     /****************************************************/
  88.     
  89.     RectRgn( (*gWindow).visRgn, &qd.screenBits.bounds );
  90.     InvalRect( &qd.screenBits.bounds );
  91.     
  92.     /*************************************************/
  93.     /* Set the global MBarHeight to 0 to prevent any */
  94.     /*    other apps from writing to the menu bar.     */
  95.     /*************************************************/
  96.     
  97.     *((short *)0xbaa) = 0;
  98. }
  99.  
  100. void drawWindow()
  101. {
  102.     ForeColor( redColor );
  103.     PaintRect( &qd.screenBits.bounds );
  104.     
  105.     MoveTo( 15, 15 );
  106.     DrawString( "\pPress any key to quit." );
  107. }
  108.  
  109. void doEventLoop()
  110. {
  111.     EventRecord event;
  112.     WindowPtr   window;
  113.     short       clickArea;
  114.     Rect        screenRect;
  115.  
  116.     for (;;)
  117.     {
  118.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  119.         {
  120.             if (event.what == mouseDown)
  121.             {
  122.                 clickArea = FindWindow( event.where, &window );
  123.                 
  124.                 if (clickArea == inDrag)
  125.                 {
  126.                     screenRect = (**GetGrayRgn()).rgnBBox;
  127.                     DragWindow( window, event.where, &screenRect );
  128.                 }
  129.                 else if (clickArea == inContent)
  130.                 {
  131.                     if (window != FrontWindow())
  132.                         SelectWindow( window );
  133.                 }
  134.                 else if (clickArea == inGoAway)
  135.                     if (TrackGoAway( window, event.where ))
  136.                         return;
  137.             }
  138.             else if (event.what == keyDown || event.what == autoKey)
  139.                 ExitToShell();
  140.             else if (event.what == updateEvt)
  141.             {
  142.                 window = (WindowPtr)event.message;    
  143.                 SetPort( window );
  144.                 
  145.                 BeginUpdate( window );
  146.                 drawWindow();
  147.                 EndUpdate( window );
  148.             }
  149.             else if (event.what == activateEvt)
  150.             {
  151.                 HideIt();
  152.             }
  153.         }
  154.     }
  155. }