Path: utzoo!attcan!uunet!super!udel!gatech!rutgers!apple!bionet!agate!pasteur!ames!lll-lcc!well!ewhac From: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Newsgroups: comp.sys.amiga.tech Subject: Re: following the sliding prop gadget Summary: You want CloseWindowSafely() Message-ID: <7288@well.UUCP> Date: 4 Oct 88 08:33:09 GMT References: <2877@mtuxo.att.com> <4875@cbmvax.UUCP> <7263@well.UUCP> <2937@mtuxo.att.com> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Distribution: na Organization: Hole Earth 'Lectronic Loss (or words to that effect) Lines: 64 Quote: "I plan to live forever -- or die trying." -- Vila In article <2937@mtuxo.att.com> tas@mtuxo.att.com (XMPC2-T.SKROBALA) writes: >I have the LockIBase() >there because all my windows share a common IDCMP port, and I want to >make sure that I don't process any messages left over from windows that have >been closed, so I check any incoming message's IDCMPWindow to make sure >that it still exists. I'm not terribly satisfied with this approach >(especially now that it's obviously causing me problems), and I've gotten >the idea here that there is a way to flush all of a window's pending messages >when it is closed. Is this as simple as installing a GetMsg() loop before >CloseWindow(), or is there more to it? > You want the routine CloseWindowSafely(): -------- /* CloseWindowSafely() * This module should be used whenever you are sharing an IDCMP * message port with more than one window. Rather than calling CloseWindow(), * you should use CloseWindowSafely(). This will keep Intuition from * Guru Meditation, and thus is considered a good thing. You should still * use CloseWindow for the very last window you close. * The reason this is needed is because Intuition will re-claim * any outstanding messages for a window when the window is closed. But... * it can't take them out of your message port. Thus, you will receive * invalid messages and bad things will happen. Very bad things. * This code is a slightly condensed version of the same routine * written by Neil Katin of Amiga for the April '86 Commodore Developers * Newsletter, Amiga Mail (tm). */ #include #include void CloseWindowSafely (win) register struct Window *win; { register struct IntuiMessage *msg; register struct IntuiMessage *succ; register struct MsgPort *mp = (struct MsgPort *) win -> UserPort; Forbid (); msg = (struct IntuiMessage *) mp -> mp_MsgList.lh_Head; while (succ = (struct IntuiMessage *) msg -> ExecMessage.mn_Node.ln_Succ) { if (msg -> IDCMPWindow == win) { Remove (msg); ReplyMsg (msg); } msg = succ; } win -> UserPort = NULL; ModifyIDCMP (win, 0L); Permit (); CloseWindow (win); } -------- Enjoy. _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape INET: well!ewhac@ucbvax.Berkeley.EDU \_ -_ Recumbent Bikes: UUCP: pacbell > !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Work FOR? I don't work FOR anybody! I'm just having fun." -- The Doctor