Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site ism780c.UUCP Path: utzoo!linus!decvax!ittatc!dcdwest!sdcsvax!sdcrdcf!ism780c!tim From: tim@ism780c.UUCP (Tim Smith) Newsgroups: net.micro.mac Subject: Re: How about a sample DA source? (Ok, here is a sample DA) Message-ID: <202@ism780c.UUCP> Date: Thu, 26-Dec-85 23:48:31 EST Article-I.D.: ism780c.202 Posted: Thu Dec 26 23:48:31 1985 Date-Received: Sat, 28-Dec-85 13:01:36 EST References: <758@unc.unc.UUCP> <192@ism780c.UUCP> Reply-To: tim@ism780c.UUCP (Tim Smith) Distribution: net Organization: Interactive Systems Corp., Santa Monica, CA Lines: 156 >In article <758@unc.unc.UUCP> palmer@unc.UUCP (Thomas C. Palmer) writes: > > I'm having considerable trouble writing a DA in Megamax C. > Instead of going into gory details, would some kind soul either > post or mail me a sample DA in Megamax C? (Wouldn't a DA skel > be a nice Christmas present?) Thanks much. > Ok, here is a sample DA written in Megamax C. It doesn't do anything spectacular. It just displays a window with the mouse location shown in local and global coordinates. As for a DA Skel, MacTutor had a DA called Shell, in Megamax C, a few issues ago. It puts up a window and a menu. It mostly works, except for update events ( see note in my DA source below ). If you can get this from someone, and it seems to bomb in some way related to menus, then look at your RMaker output. My copy of RMaker puts bad stuff in the resource ID of the menu defintion proc, which I have to fix using ResEdit before it works. Maybe Megamax has an old version of RMaker? Anyway, this has nothing to do with the DA below! ------------------------- Cut Here --------------------------- /* * MousePosition DA : display mouse position in a window. Both * global and local positions are shown. Local position is in the * coordinate system of whatever FrontWindow() feels like returning. */ /* * Notes: * Don't forget to tell the linker that this is a DRVR! * * Don't forget to install the INIT and DATA resources * when you install the DA. ( FONT/DA mover should do this for * for you, but ResEdit doesn't ). */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ACC( 0x2400, 10, 0, 0, 7, "Mouse @" ) accopen( dctl, pb ) dctlentry *dctl; paramblockrec *pb; { WindowPeek mywindow; Rect wr; if ( dctl->dCtlWindow == NULL ) { SetRect( &wr, 50, 50, 150, 74 ); mywindow = NewWindow( NULL, &wr, "Mouse", 0, RDocProc, -1L, -1, 0L ); mywindow->windowKind = dctl->dCtlRefNum; dctl->dCtlWindow = mywindow; } else CloseDeskAcc( dctl->dCtlRefNum ); return 0; } accclose( dctl, pb ) dctlentry *dctl; paramblockrec *pb; { DisposeWindow( dctl->dCtlWindow ); dctl->dCtlWindow = NULL; return 0; } accctl( dctl, pb ) dctlentry *dctl; paramblockrec *pb; { WindowPtr mywindow; GrafPtr saveport; char outstr[ 100 ]; Point mouseloc, Gmouseloc; static int lasth = -1, lastv = -1; Rect wr; mywindow = dctl->dCtlWindow; if ( mywindow == NULL ) return 0; GetPort( &saveport ); SetPort( FrontWindow() ); /* to get local coordinates */ GetMouse( &mouseloc ); Gmouseloc = mouseloc; LocalToGlobal( &Gmouseloc ); if ( mouseloc.a.v != lastv || mouseloc.a.h != lasth ) { SetPort( (GrafPtr)mywindow ); SetRect( &wr, 0, 0, 200, 100 ); EraseRect( &wr ); sprintf( outstr, "L:%d,%d", lasth = mouseloc.a.h, lastv = mouseloc.a.v ); MoveTo( 4, 11 ); DrawString( outstr ); sprintf( outstr, "G:%d,%d", Gmouseloc.a.h, Gmouseloc.a.v ); MoveTo( 4, 23 ); DrawString( outstr ); } /* * Call {Begin,End}Update to clear the update event. Both * the clock DA that comes with Megamax C, and the Shell DA * from MacTutor fail to do this, which is why they mess up * windows behind their windows when run from an application * other than the Finder. Here is what happens if you leave * out the {Begin,End}Update calls: * * As soon as the DA window becomes the frontmost window * that needs updating, GetNextEvent() starts reporting * an update event for it. Since update events are not * placed in the event queue, it keeps reporting this * update event until something is done about it. It does * not report update events for any windows that are behind * the DA window. * * The application ignores these update events, since they * are for a DA window. Hence, things don't get updated * until you close the DA. * * The strange thing is that this does NOT happen when you * run under the Finder. It looks like the Finder notices * that there is a malfunctioning DA and deals with it. * I haven't a clue as to WHY it does this. * * I suspect that Megamax and the MacTutor author only * tested their DAs under the finder. */ BeginUpdate( mywindow ); EndUpdate( mywindow ); SetPort( saveport ); return 0; } accprime() {} accstatus() {} ------------------------------ Cut Me! -------------------------------- -- Tim Smith sdcrdcf!ism780c!tim || ima!ism780!tim || ihnp4!cithep!tim