EAO102@psuvm.psu.edu (Ernie Oporto) (06/24/91)
I'm having trouble updating a few windows in a program. I'm still a novice mac programmer, (as if you couldn't tell), so please bear with me. I'll get there. I use the UpdateMyPictures subprogram below to update at UpdateEvt's. However, only the gStasisWindow gets updated and all the rest keep their areas erased of whatever was covered in them. Each window has a PICT that is unique to it, so I use UpdateMyPictures to tell which is which and what PICT needs to be accessed and drawn im that window. I use the Mac Programming Primer to do my programming, so if you have any references from there or any advice/algorithms/code you'd like to pass on,please do. Any help would be really appreciated. I do not own any of the Inside Mac or Mac Revealed (I'll get them when I can someday afford it), so dont give references for them. I would really like to know what routines people use and I'd like to see any source code that would help me out or solve my problem. The code below is a sample of what is in my program. I only included the important parts to show how I created my windows and how I *tried* to keep them all updated: /*** main ***/ main() { ToolBoxInit(); SplashInit(); SetUpDragRect(); SetUpSizeRect(); MenuBarInit(); StasisInit(); ClockInit(); MainLoop(); } /*** ToolBoxInit ***/ ToolBoxInit() { InitGraf(&thePort); InitFonts(); FlushEvents(everyEvent,REMOVE_ALL_EVENTS); InitWindows(); InitMenus(); TEInit(); InitDialogs(NIL_POINTER); InitCursor(); } /*** SplashInit ***/ SplashInit() { CreateWindow(BASE_RES_ID,gSplashWindow,gSplashPict); while(!Button()); DisposeWindow(gSplashWindow); } /*** StasisInit ***/ StasisInit() { CreateWindow(BASE_RES_ID+1,gStasisWindow,gStasisPict); } /*** ClockInit ***/ ClockInit() { gClockWindow=GetNewWindow(BASE_RES_ID+10,NIL_POINTER,MOVE_TO_FRONT); ShowWindow(gClockWindow); SetPort(gClockWindow); } /*** MainLoop ***/ MainLoop() { gDone=FALSE; gWNEImplemented=(NGetTrapAddress(WNE_TRAP_NUM,ToolTrap)!= NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap)); while(gDone==FALSE) { HandleEvent(); } } /*** HandleEvent ***/ HandleEvent() { char theChar; GrafPtr oldPort; if (gWNEImplemented) WaitNextEvent(everyEvent,&gTheEvent,MIN_SLEEP,NIL_MOUSE_REGION); else { SystemTask(); GetNextEvent(everyEvent,&gTheEvent); } switch(gTheEvent.what) { . . . case updateEvt: if(!IsDAWindow(gTheEvent.message)) { GetPort(&oldPort); SetPort(gTheEvent.message); BeginUpdate(gTheEvent.message); UpdateWindows(); EndUpdate(gTheEvent.message); SetPort(oldPort); } break; } } /*** HandleFileChoice ***/ HandleFileChoice(theItem) int theItem; { WindowPtr whichWindow; switch(theItem) { case HEIGHT_ITEM: CreateWindow(BASE_RES_ID+2,gHeightWindow,gHeightPict); break; case WEIGHT_ITEM: CreateWindow(BASE_RES_ID+3,gWeightWindow,gWeightPict); break; case HAIR_ITEM: CreateWindow(BASE_RES_ID+4,gHairWindow,gHairPict); break; case EYES_ITEM: CreateWindow(BASE_RES_ID+5,gEyesWindow,gEyesPict); break; case AGE_ITEM: CreateWindow(BASE_RES_ID+6,gAgeWindow,gAgePict); break; case ADDRESS_ITEM: CreateWindow(BASE_RES_ID+8,gAddressWindow,gAddressPict); break; case PHONE_ITEM: CreateWindow(BASE_RES_ID+9,gPhoneWindow,gPhonePict); break; case CLOSE_ITEM: if(((whichWindow=FrontWindow())!=gStasisWindow)&& ((whichWindow=FrontWindow())!=gClockWindow)) { if((whichWindow=FrontWindow())!=NIL_POINTER) DisposeWindow(whichWindow); } break; case QUIT_ITEM: gDone=TRUE; break; } } /*** CreateWindow ***/ CreateWindow(theResId,theWindow,thePict) int theResId; WindowPtr theWindow; PicHandle thePict; { theWindow=GetNewWindow(theResId,NIL_POINTER,MOVE_TO_FRONT); ShowWindow(theWindow); SetPort(theWindow); thePict=GetPicture(theResId); DrawMyPicture(thePict,theWindow); } /*** DrawMyPicture ***/ DrawMyPicture (thePicture,pictureWindow) PicHandle thePicture; WindowPtr pictureWindow; { Rect myRect; myRect=pictureWindow->portRect; CenterPict(thePicture,&myRect); SetPort(pictureWindow); DrawPicture(thePicture,&myRect); } UpdateWindows() { if ((WindowPtr)gTheEvent.message==gStasisWindow) DrawMyPicture(gStasisPict,gStasisWindow); if ((WindowPtr)gTheEvent.message==gHeightWindow) DrawMyPicture(gHeightPict,gHeightWindow); if ((WindowPtr)gTheEvent.message==gWeightWindow) DrawMyPicture(gWeightPict,gWeightWindow); if ((WindowPtr)gTheEvent.message==gHairWindow) DrawMyPicture(gHairPict,gHairWindow); if((WindowPtr)gTheEvent.message==gEyesWindow) DrawMyPicture(gEyesPict,gEyesWindow); if ((WindowPtr)gTheEvent.message==gAgeWindow) DrawMyPicture(gAgePict,gAgeWindow); if ((WindowPtr)gTheEvent.message==gAddressWindow) DrawMyPicture(gAddressPict,gAddressWindow); if ((WindowPtr)gTheEvent.message==gPhoneWindow) DrawMyPicture(gPhonePict,gPhoneWindow); } --Ernie SHOKK Oporto ******** * * ******** * ** * ** EAO102@PSUVM.PSU.EDU ** * * * * * ** * ** Student **** ******** * * **** **** Computer Laboratory ** * * * * * ** * ** Attendant of the ******** * * ******** * ** * ** PennState University Center for Academic Computing