home *** CD-ROM | disk | FTP | other *** search
- #include <skeleton.h> /* Note: You must give you C++ linker the access path to the */
- /* Skeleton ƒ folder that is in you machine or it will */
- /* not be able to find it. */
-
-
- /* This is where your program will first start to execute.*/
-
- void main(void)
- {
-
- InitToolBox();
-
- InitOtherStuff();
-
- SetUpMenus();
-
- EventLoop();
-
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void InitToolBox(void)
- {
-
- InitGraf(&qd.thePort); /* These are calls to the Macintosh Programers ToolBox. */
- InitFonts(); /* the calls tell the Macinthos OS what types of functions */
- InitWindows(); /* will using in our program. For instance if we ar going */
- InitMenus(); /* to use menus in the MenuBar, we must first, make a call */
- TEInit(); /* to InitMenus(); to let the OS know that we want to use */
- InitDialogs(nil); /* the MenuHandler built into the OS. This is also true */
- InitCursor(); /* windows, dialogs and many other things we want to use. */
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void InitOtherStuff(void)
- {
- /*Creat a rect with the boundries of 4 pixles from the edge of the screen. The 24 pixle*/
- /*boder on the top ajusts for the Menu Bar. This rect will be used to confine the area */
- /*in which windows can be moved.*/
- SetRect(&dragRect, 4, 24, qd.screenBits.bounds.right - 4, qd.screenBits.bounds.bottom - 4);
-
- appleMenu = GetMenu(appleID); /* Read Apple menu from resource file and */
- /* We will need to reference this in the */
- /* SetUpMenus routine.*/
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void SetUpMenus(void)
- {
- Handle MenuBar;
-
- MenuBar = GetNewMBar(128); /* read Mbar #128 from recource file */
-
- SetMenuBar(MenuBar); /* Set the current MenuBar to "MenuBar" */
-
- AddResMenu(appleMenu, 'DRVR'); /* add desk accessory names to Apple menu */
-
- DrawMenuBar(); /* and draw menu bar */
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void EventLoop(void)
- {
-
- do {
- SystemTask();
-
- if (WaitNextEvent(everyEvent, &myEvent, 5L, NULL)) {
- switch (myEvent.what) { /* The case on event type */
-
- case mouseDown:
- switch (FindWindow(myEvent.where, &whichWindow)) {
-
- case inSysWindow: /* The desk accessory window */
- SystemClick(&myEvent, whichWindow);
- break;
-
- case inMenuBar: /* The Menu bar */
- MenuHandler(MenuSelect(myEvent.where)); /* Determine Which menu it was */
- break;
-
- case inDrag: /* Title bar */
- DragWindow(whichWindow, myEvent.where, &dragRect); /* Drag Manager */
- break;
-
- case inContent: /* The body of one of our application's windows */
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow); /* Make it active if not if it wasn't*/
- break;
-
- case inGoAway: /* Close box of a window */
- if (TrackGoAway( whichWindow, myEvent.where ))
- DisposeWindow(whichWindow);
- break;
- }
- break;
-
- case updateEvt: /* Update the window. */
- if ((WindowPtr) myEvent.message == FrontWindow()) {
- BeginUpdate((WindowPtr) myEvent.message);
-
- EndUpdate((WindowPtr) myEvent.message);
- }
- break;
-
- case keyDown:
- case autoKey: /* A key was pressed once or held down to repeat */
- theChar = (myEvent.message & charCodeMask); /* get the char */
- /*
- ** If Command key down, do it as a Menu Command.
- */
- if (myEvent.modifiers & cmdKey)
- MenuHandler(MenuKey(theChar));
-
- break;
-
- }
- }
-
-
- } while (!quit);
-
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void MenuHandler(long int mResult)
- {
-
- short theItem, /* menu item number from mResult low-order word */
- theMenu; /* menu number from mResult high-order word */
- Str255 name; /* desk accessory name */
-
-
-
- theItem = LoWord(mResult); /* call Toolbox Utility routines to */
- theMenu = HiWord(mResult); /* set menu item number and menu */
-
- switch (theMenu) { /* switch on menu ID */
-
- case appleID:
- if (theItem == 1){
- ShowAboutMeDialog();
-
- }
-
- else {
- GetItem(appleMenu, theItem, name);
- OpenDeskAcc(name);
- }
- break;
-
- case fileID:
- if (theItem == 1){
- quit = true;
- }
-
-
- break;
-
-
-
-
- }
-
- HiliteMenu(0); /* Unhighlight menu title */
- /* (highlighted by MenuSelect) */
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
- void ShowAboutMeDialog(void)
- {
- DialogPtr aboutDialog;
- short itemHit;
-
- aboutDialog = GetNewDialog(128, nil, (WindowPtr) -1); /* Put up Dialog number 128 */
-
- SetDialogDefaultItem(aboutDialog, 1); /* Frame the ok button, and */
- /* Link it to the Return key*/
-
- ModalDialog(nil, nil); /* Wait for a key to be hit */
-
- DisposDialog(aboutDialog); /* Dispose of the Dlog box. */
- }
-
- /*---------------------------------------------------------------------------------------------*/
- /*---------------------------------------------------------------------------------------------*/
-
-