isle@eleazar.dartmouth.edu (Ken Hancock) (08/15/89)
I'm writing a DA, and like all good little DA's, it will remove it's menu from the MenuBar when not frontmost. The only probelm is, that no matter what code I use, I sometimes get a Disposed menu in the menubar (clicking on it will of course crash the system...) The code I'm using is included below: void UpdateMBar(dce) DCtlPtr dce; { register WindowPeek wptr = (WindowPeek) FrontWindow(); /* If our window isn't the frontmost, hide the * menu to avoid menubar clutter. */ if (wptr) { if (wptr->windowKind == dce->dCtlRefNum) { if (!GetMHandle(dce->dCtlMenu)) { InsertMenu(myMenuHandle,0); DrawMenuBar(); } } else if (GetMHandle(dce->dCtlMenu)) { DeleteMenu(dce->dCtlMenu); DrawMenuBar(); } } } Now the only time that the menu is actually Disposed of is after I receive an accClose and have closed the driver. Does anyone know what I'm doing wrong? Thanks in advance -- Ken Ken Hancock '90 | E-mail: (BITNET/UUCP/INTERNET) Computer Resource Center Consultant | isle@eleazar.dartmouth.edu ------------------------------------+--------------------------------------- DISCLAIMER? I don't get paid enough to worry about disclaimers.
tim@hoptoad.uucp (Tim Maroney) (08/18/89)
In article <15029@dartvax.Dartmouth.EDU> isle@eleazar.dartmouth.edu (Ken Hancock) writes: >I'm writing a DA, and like all good little DA's, it will >remove it's menu from the MenuBar when not frontmost. >The only probelm is, that no matter what code I use, >I sometimes get a Disposed menu in the menubar >(clicking on it will of course crash the system...) > >Now the only time that the menu is actually Disposed of is after >I receive an accClose and have closed the driver. Does anyone know >what I'm doing wrong? Your code looks OK, but it's too interpretive. The menu bar is a system data structure and where Inside Macintosh imposes a specific protocol on how to use the system data structure, you should try to abide by it as closely as possible. IM I-446-7 makes it clear that desk accessories should install their menus when they get activate events and remove them when they get deactivate events. You seem to be doing it on every event instead, checking to see if your window is the front window. Try it the traditional way and see if there's any change. And no, I don't know exactly what's happening there. I would speculate that someone is doing a GetMenuBar while your menu is up, then restoring it with SetMenuBar when your menu is not up. The Menu Manager does some fairly tricky things with the menu list and this could cause problems -- as I recall, I had a similar problem with Moire a little more than a year ago. This may or may not be the answer, but in any case, try it the traditional way and see what happens. -- Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com "What's bad? What's the use of turning? In Hell I'll be there a-burning! Meanwhile, think of what I'm earning! All on account of my name." - Bill Sykes, "Oliver"