Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!lll-lcc!pyramid!voder!apple!lsr From: lsr@apple.UUCP Newsgroups: comp.sys.mac Subject: Re: Finding out if there are no windows on the screen Message-ID: <1037@apple.UUCP> Date: Mon, 15-Jun-87 13:50:24 EDT Article-I.D.: apple.1037 Posted: Mon Jun 15 13:50:24 1987 Date-Received: Wed, 17-Jun-87 01:32:49 EDT References: <8259@ut-sally.UUCP> <1036@apple.UUCP> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Organization: Advanced Technology Group, Apple Computer Lines: 55 Keywords: Mac Programming Question In article <1036@apple.UUCP> han@apple.UUCP (Byron Han) writes: >In article <8259@ut-sally.UUCP>, brian@ut-sally.UUCP (Brian H. Powell) writes: >> >> Motivation: I'm writing a program that can have several windows and desk >> accessories on the screen. When there are no windows or DAs on the screen, I >> want the Close item in the File menu to be dimmed. >> >Try waiting until there is a Null Event returned from GNE. And then check >to see if FrontWindow = Nil, then disable else Enable > >or alternatively, after each MouseDown in the GoAway region of the window, or >each call to SystemClick, check the frontwindow to see if it is >NIL and then disable/enable the CLOSE item. > >The second would give better results because if the user clicks in the close >box and has other events queued up immediately after, the CLOSE item may >not be immediately disabled. Testing FrontWindow = NIL is the way to go, but I would make the check just before calling MenuSelect or MenuKey. The item doesn't have to be grayed out immediately, since it can't be seen unless the menu is pulled down. This has the advantages that it is always results in the correct menu highlighting (ie, you don't have to depend on catching a DA being closed) and the code only runs when it matters (just before a menu is pulled down). In addition, if the FrontWindow is not NIL, you should check to see if it has a goAway box. If the window does not have a goAway box, then Close should be disabled. In MacApp, we try to set up the menu state just before the menu is pulled down. If you do this, there are a couple of things to watch out for. You have to set up every menu. Once you call MenuSelect, the user can pull down any menu without your program getting a chance to intervene. You have to set up the menus before calling MenuKey as well. Even though the menu is not pulled down, MenuKey looks at the enable flags. If your Close item has a command key equivalent, then it can be chosen unless grayed out. Lastly, this technique doesn't work for graying out menu titles. It is unacceptable for a menu title to be grayed out after the user clicks on the menu bar. Menu titles have to be grayed out separately. -- Larry Rosenstein Object Specialist Apple Computer AppleLink: Rosenstein1 UUCP: {sun, voder, nsc, mtxinu, dual}!apple!lsr CSNET: lsr@Apple.com