OpenDeskAcc
OpenDeskAcc Execute or reactivate a desk accessory
#include <Desk.h> Desk Manager
short OpenDeskAcc(daName );
Str255 daName ; p-string name of DA to open
returns driver reference number (if successful)
Call OpenDeskAcc when the user selects a desk accessory from your Apple
() menu. It loads the DA into memory (if not already there) and passes
control to it.
daName is the address of a pascal-style length-prefixed string containing
the name of the DA to open. It is normally a value obtained via
Returns: a short; the driver reference number of the just opened DA. If the
call fails, the return value is un defined, so don't depend on this value.

Notes: OpenDeskAcc should be used in all interactive applications to enable the
user to access DAs (i.e., all interactive applications).
Note: Some older DAs might leave their windows active. It is wise to
surround this call with GetPort...SetPort.
Before making the call, you may want to enable standard menu items such
as Close, Undo, etc. You also may wish to disable all other menu items
(as recommended in IM).
In addition, you will need a piece of code to close the DA. When the user
choses Close from your File menu, and the frontmost window is not
yours, you should call CloseDeskAcc. Your application should also call
SystemEdit to take care of Edit menu selections for DAs.
The example below outlines the overhead and general sequence of
operations surrounding a call to OpenDeskAcc.
Example
#include <Menus.h>
#include <Desk.h>
void DoAboutMyProg(void);
/*... when setting up the menus ...*/
# define APPLE_RES_ID 1
# define APPLE_MENU 1
MenuHandle appleMenu;
appleMenu = NewMenu( APPLE_RES_ID, "\p\024" ); /* create apple menu
*/
AppendMenu( appleMenu, "\pAbout MyProg...;(-" );
AddResMenu( appleMenu, 'DRVR' ); /* Add DA list */
InsertMenu( appleMenu, 0 ); /* install in menu bar */
/*... in the event loop ... */
EventRecord theEvent;
WindowPtr whichWindow;
Str255 daName;
long mr; /* MenuSelect() return code */
GrafPtr savePort;
if(WaitNextEvent(everyEvent, & theEvent, 0, nil)) {
if ( theEvent.what == mouseDown ) {
switch ( FindWindow( theEvent.where, & whichWindow ) ) {
case inMenuBar:
mr = MenuSelect( theEvent.where ); /* user interaction */
if ( HiWord( mr ) == APPLE_MENU ) { /* in apple menu? */
if ( LoWord( mr ) == 1 ) {
DoAboutMyProg(); /* About MyProg... */
break;
} /* else must be DA */
DisableItem( editMenu, emOptions );
/* disable unneeded items */
DisableItem( editMenu, emFont );
EnableItem( fileMenu, fmClose ); /* enable Close item */
GetItem( appleMenu, LoWord(mr), daName );
/* get DA name */
GetPort( &savePort ); /* a precaution */
OpenDeskAcc( daName ); /* activate the DA */
SetPort( savePort ); /* some insurance */
EnableItem( editMenu, emOptions ); /* re-enable items */
EnableItem( editMenu, emFont );
break;
}
case inDrag:
/* ... etc ... */
}
}
}