milt@mist.cs.orst.edu (Milt Sagen) (01/29/88)
I'm making my first attempt at writing a DA using LightSpeed C and I'm not having very much luck. The code, which follows, puts up a single window and should only handle update events. The window does get created by when it is the active window, the windows below it will no longer update correctly. Also when it is the top window and I try to quit the underlying application the computer hangs. It is as if the DA has taken over the machine and is intercepting all events. Could one of you people with more experience than I (which isn't much) tell me what I left out or what I am doing that is entirely wrong. Thanks THE CODE: #include <WindowMgr.h> #include <DeviceMgr.h> #include <EventMgr.h> #ifndef NULL #define NULL 0L #endif NULL DCtlPtr dce ; main(p, d, n) cntrlParam *p ; DCtlPtr d ; int n ; { WindowPtr curWindow ; Rect theRect ; WindowPeek theWPeek ; if( d->dCtlStorage == 0 ) { if( n == 0 ) { /* open the DA */ SysBeep(3) ; CloseDriver( d->dCtlRefNum ) ; } return( 0 ) ; } dce = d ; switch( n ) { case 0 : /* open the DA */ dce->dCtlEMask = 64 ; /* update events only */ GetPort( &curWindow ) ; if( dce->dCtlWindow == NULL ) { /* then allocate the window */ SetRect( &theRect, 156, 71, 356, 271 ) ; dce->dCtlWindow = NewWindow( 0L, &theRect, "\pMy DA", false, rDocProc, (Ptr)-1, true, 0L ) ; theWPeek = (WindowPeek) dce->dCtlWindow ; theWPeek->windowKind = dce->dCtlRefNum ; } SetPort( curWindow ) ; break ; case 2 : /* dispatch events */ switch( p->csCode ) { case accEvent : DoEvents( (EventRecord *) p->csParam ) ; break ; } break ; case 4 : GetPort( &curWindow ) ; DisposeWindow( dce->dCtlWindow ) ; dce->dCtlWindow = NULL ; SetPort( curWindow ) ; break ; } return(0) ; } DoEvents( theEvent ) EventRecord *theEvent ; { WindowPtr curWindow ; switch( theEvent->what ) { case updateEvt : BeginUpdate( (WindowPtr) theEvent->message ) ; SetPort( (WindowPtr) theEvent->message ) ; EndUpdate( (WindowPtr) theEvent->message ) ; break ; } /* end of switch on theEvent.what */ } END OF CODE: I hope the spacing looks alright on your terminals I had to redo some of it to get it to look readable on mine. Milt Sagen Dept of Physics Oregon STate U. Corvallis, OR 97331 milt%orstph.UUCP@orstcs.CS.ORST.EDU