home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Toolbox / HideMenuBar / HideMenuBar.c next >
Encoding:
C/C++ Source or Header  |  1992-10-14  |  3.2 KB  |  145 lines  |  [TEXT/KAHL]

  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. /* Global Variable Definitions */
  21.  
  22. WindowPtr    gWindow;
  23.  
  24. void initMac();
  25.  
  26. void HideMenuBar();
  27. void HideIt();
  28. void drawWindow();
  29. void doEventLoop();
  30.  
  31. main()
  32. {
  33.     initMac();
  34.     
  35.     HideMenuBar();
  36.     
  37.     doEventLoop();
  38. }
  39.  
  40. void initMac()
  41. {
  42.     MaxApplZone();
  43.  
  44.     InitGraf( &thePort );
  45.     InitFonts();
  46.     InitWindows();
  47.     InitMenus();
  48.     TEInit();
  49.     InitDialogs( nil );
  50.     InitCursor();
  51.     FlushEvents( 0, everyEvent );
  52. }
  53.  
  54. void HideMenuBar()
  55. {
  56.     Rect    rect;
  57.     
  58.     gWindow = NewCWindow( 0L, &rect, "\p", false, plainDBox,
  59.                             (WindowPtr)-1L, true, 0L );                        
  60.     
  61.     MoveWindow( gWindow, qd.screenBits.bounds.left, qd.screenBits.bounds.top, true );
  62.     SizeWindow( gWindow, qd.screenBits.bounds.right - qd.screenBits.bounds.left,
  63.                         qd.screenBits.bounds.bottom - qd.screenBits.bounds.top, false );
  64.     
  65.     SetPort( gWindow );
  66.     ShowWindow( gWindow );
  67.     
  68.     TextMode( geneva );
  69.     TextSize( 9 );
  70.     TextMode( srcXor );
  71. }
  72.  
  73. void HideIt()
  74. {    
  75.     /****************************************************/
  76.     /* Set the window's visRgn to include the menu bar. */
  77.     /****************************************************/
  78.     
  79.     RectRgn( (*gWindow).visRgn, &qd.screenBits.bounds );
  80.     InvalRect( &qd.screenBits.bounds );
  81.     
  82.     /*************************************************/
  83.     /* Set the global MBarHeight to 0 to prevent any */
  84.     /*    other apps from writing to the menu bar.     */
  85.     /*************************************************/
  86.     
  87.     *((short *)0xbaa) = 0;
  88. }
  89.  
  90. void drawWindow()
  91. {
  92.     ForeColor( redColor );
  93.     PaintRect( &qd.screenBits.bounds );
  94.     
  95.     MoveTo( 15, 15 );
  96.     DrawString( "\pPress any key to quit." );
  97. }
  98.  
  99. void doEventLoop()
  100. {
  101.     EventRecord event;
  102.     WindowPtr   window;
  103.     short       clickArea;
  104.     Rect        screenRect;
  105.  
  106.     for (;;)
  107.     {
  108.         if (WaitNextEvent( everyEvent, &event, 0, nil ))
  109.         {
  110.             if (event.what == mouseDown)
  111.             {
  112.                 clickArea = FindWindow( event.where, &window );
  113.                 
  114.                 if (clickArea == inDrag)
  115.                 {
  116.                     screenRect = (**GetGrayRgn()).rgnBBox;
  117.                     DragWindow( window, event.where, &screenRect );
  118.                 }
  119.                 else if (clickArea == inContent)
  120.                 {
  121.                     if (window != FrontWindow())
  122.                         SelectWindow( window );
  123.                 }
  124.                 else if (clickArea == inGoAway)
  125.                     if (TrackGoAway( window, event.where ))
  126.                         return;
  127.             }
  128.             else if (event.what == keyDown || event.what == autoKey)
  129.                 ExitToShell();
  130.             else if (event.what == updateEvt)
  131.             {
  132.                 window = (WindowPtr)event.message;    
  133.                 SetPort( window );
  134.                 
  135.                 BeginUpdate( window );
  136.                 drawWindow();
  137.                 EndUpdate( window );
  138.             }
  139.             else if (event.what == activateEvt)
  140.             {
  141.                 HideIt();
  142.             }
  143.         }
  144.     }
  145. }