home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 092.lha / ColorFull / safeclose.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  1.5 KB  |  46 lines

  1. /* CloseWindowSafely()
  2. *       This module should be used whenever you are sharing an IDCMP
  3. * message port with more than one window.  Rather than calling CloseWindow(),
  4. * you should use CloseWindowSafely().  This will keep Intuition from
  5. * Guru Meditation, and thus is considered a good thing.  You should still
  6. * use CloseWindow for the very last window you close.
  7. *       The reason this is needed, is because Intuition will re-claim
  8. * any outstanding messages for a window when the window is closed. But...
  9. * it can't take them out of your message port. Thus, you will receive
  10. * invalid messages and bad things will happen.  Very bad things.
  11. *       This code is a slightly condensed version of the same routine
  12. * written by Neil Katin of Amiga for the April '86 Commodore Developers
  13. * Newsletter, Amiga Mail (tm).
  14. */
  15.  
  16. #include "standard.h"
  17.  
  18. void CloseWindowSafely( p_wind )
  19.    struct Window   *p_wind;
  20.    {
  21.    register struct IntuiMessage    *msg;
  22.    register struct IntuiMessage    *succ;
  23.    register struct Window          *win = p_wind;
  24.    register struct MsgPort         *mp = (struct MsgPort *)win->UserPort;
  25.  
  26.    Forbid();
  27.  
  28.    msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  29.  
  30.    while ( succ=(struct IntuiMessage *)msg->ExecMessage.mn_Node.ln_Succ )
  31.       {
  32.       if ( msg->IDCMPWindow == win )
  33.          {
  34.          Remove ( msg );
  35.          ReplyMsg( msg );
  36.          }
  37.       msg = succ;
  38.       }
  39.    win->UserPort = NULL;
  40.    ModifyIDCMP( win, 0L );
  41.    Permit();
  42.    CloseWindow( win );
  43.    }
  44.  
  45.  
  46.