Article View: comp.sys.mac
Article #16870Re: Finding out if there are no windows on the screen
From: Byron Han
Date: Mon, 15 Jun 1987 15:17
Date: Mon, 15 Jun 1987 15:17
65 lines
3080 bytes
3080 bytes
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.
>
> The brute force method is to build the menu each time the user clicks in
> the menu bar.
>
> Is there a more elegant solution?
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.
In fact, the best thing is to do both. Because, some action in the DA
(via some keydown) may cause the window to go away. But then you should
have some sanity checks in the CLose ROutine.
I typically use this routine which is called in response to a mousedown in the
GoAway part of the window that is the frontwindow (otherwise selectwindow is
called) or to selecting CLOSE in the FILE menu.
NOTE this is not meant to be final word - there are many ways to improve this
code and this serves as a simple example.
PROCEDURE DoClose;
VAR
theWindow : WindowPtr;
theWIndowPeek : WindowPeek;
BEGIN
theWindow = FrontWindow;
if theWindow <> NIL do begin
theWIndowPeek = WindowPeek(theWIndow);
if theWindowPeek^.windowKind = userKind do begin
DoCloseMyWindow(theWindow);
end
else
if theWindowPeek^.windowKind < 0 do begin
CloseDeskAcc(theWIndowPeek^.windowKind);
end;
end;
END;
Hope this helps.
=====================================================================
Byron Han | UUCP: {sun,voder,nsc,mtxinu,dual}!apple!han
Apple Computer, Inc. | CSNET: han@apple.csnet
20525 Mariani Ave, | ATTNet: 408-973-6450
Cupertino, CA 95014 | GENIE: BYRONHAN APPLELINK: HAN1
MS 27Y | CSERVE: 72167,1664
=====================================================================
All opinions and statements do not necessarily represent those of my
employer, Apple Computer Inc.
=====================================================================
Technical Details
Message-ID:
<1036@apple.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!mit-eddie!think!ames!oliveb!pyramid!voder!apple!hanReferences:
<8259@ut-sally.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!rutgers!mit-eddie!think!ames!oliveb!pyramid!voder!apple!han From: han@apple.UUCP (Byron Han) Newsgroups: comp.sys.mac Subject: Re: Finding out if there are no windows on the screen Message-ID: <1036@apple.UUCP> Date: Mon, 15-Jun-87 11:17:13 EDT Article-I.D.: apple.1036 Posted: Mon Jun 15 11:17:13 1987 Date-Received: Sun, 21-Jun-87 02:10:37 EDT References: <8259@ut-sally.UUCP> Organization: Apple Computer, Inc., Cupertino, USA Lines: 65 Keywords: Mac Programming Question