home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / intuition / IO / closewindowsafely.c next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  2.4 KB  |  78 lines

  1. /** CloseWindowSafely.c **/
  2. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  3.  *
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  5.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  6.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  7.  * information on the correct usage of the techniques and operating system
  8.  * functions presented in this example.  The source and executable code of
  9.  * this example may only be distributed in free electronic form, via bulletin
  10.  * board or as part of a fully non-commercial and freely redistributable
  11.  * diskette.  Both the source and executable code (including comments) must
  12.  * be included, without modification, in any copy.  This example may not be
  13.  * published in printed form or distributed with any commercial product.
  14.  * However, the programming techniques and support routines set forth in
  15.  * this example may be used in the development of original executable
  16.  * software products for Commodore Amiga computers.
  17.  * All other rights reserved.
  18.  * This example is provided "as-is" and is subject to change; no warranties
  19.  * are made.  All use is at your own risk.  No liability or responsibility
  20.  * is assumed.
  21.  */
  22.  
  23. #include <exec/types.h>
  24. #include <exec/nodes.h>
  25. #include <exec/lists.h>
  26. #include <exec/ports.h>
  27. #include <intuition/intuition.h>
  28.  
  29. /* this function closes an intuition window that shares a port with
  30.  * other intuition windows.
  31.  *
  32.  * It is careful to set the UserPort to null before closing, and to
  33.  * free any messages that might have been sent.
  34.  */
  35.  
  36. CloseWindowSafely(win)
  37. struct Window *win;
  38.    {
  39.    Forbid();
  40.  
  41.    /* Send back any unprocessed messages for this window */
  42.    StripIntuiMessages(win->UserPort,win);
  43.  
  44.    /* Null UserPort so Intuition won't free it */
  45.    win->UserPort = NULL;
  46.  
  47.    /* Tell Intuition to stop sending more messages */
  48.    ModifyIDCMP(win,0);
  49.  
  50.    /* Turn tasking back on */
  51.    Permit();
  52.  
  53.    /* And really close the window */
  54.    CloseWindow(win);
  55.    }
  56.  
  57. StripIntuiMessages(mp,win)
  58. struct MsgPort *mp;
  59. struct Window *win;
  60.    {
  61.    struct IntuiMessage *msg, *succ;
  62.  
  63.    msg = mp->mp_MsgList.lh_Head;
  64.  
  65.    while(succ = msg->ExecMessage.mn_Node.ln_Succ)
  66.       {
  67.       if(msg->IDCMPWindow == win)
  68.          {
  69.          /* Intuition is about to rudely free this message.
  70.           * Make sure that we have politely sent it back.
  71.           */
  72.          Remove(msg);
  73.          ReplyMsg(msg);
  74.          }
  75.       msg = succ;
  76.       }
  77.    }
  78.