home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNDSTROY.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.4 KB  |  90 lines

  1. /**
  2. *
  3. * Name        wndstroy -- Detach window from screen location
  4. *                and discard its memory structures.
  5. *
  6. * Synopsis    result = wndstroy(pwin);
  7. *
  8. *        int    result      Error code, or WN_NO_ERROR if ok.
  9. *        BWINDOW *pwin      Pointer to BWINDOW structure to
  10. *                  discard.
  11. *
  12. * Description    This function completely discards a C TOOLS PLUS window
  13. *        structure.  It does not affect any video display page.
  14. *
  15. *        Do NOT use a window structure (or any of its components)
  16. *        after destroying it via WNDSTROY.  Its memory has been
  17. *        freed.
  18. *
  19. *        An error occurs if pwin does not point to a valid window
  20. *        structure.
  21. *
  22. *        Use WNREMOVE to clean up the screen gracefully before
  23. *        destroying the window with WNDSTROY.  Use WNFORGET to
  24. *        abandon a window's border and location without
  25. *        destroying the window itself.  Use WNHIDE to make the
  26. *        window temporarily invisible.
  27. *
  28. * Returns    result          Error code, or WN_NO_ERROR if ok.
  29. *                  structure, or NIL if failure.
  30. *        *pwin          Several fields altered.
  31. *        b_pactnode[][]      Window node with active cursor.
  32. *        b_wnerr       Possible values:
  33. *                  (No change)       Success.
  34. *                  WN_BAD_WIN       *pwin is invalid.
  35. *                  WN_NOT_SHOWN       Internal error.
  36. *                  WN_BAD_NODE       Internal error.
  37. *                  WN_BAD_PAGE       Internal error.
  38. *                  WN_BAD_DEV       Internal error.
  39. *
  40. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  41. *
  42. **/
  43.  
  44. #include <string.h>
  45.  
  46. #include <bwindow.h>
  47.  
  48. #if MSC300
  49. #include <malloc.h>
  50. #else
  51. #include <stdlib.h>
  52. #endif
  53.  
  54. int wndstroy(pwin)
  55. BWINDOW *pwin;
  56. {
  57.     int dev;
  58.  
  59.     if (wnvalwin(pwin) == NIL)          /* Validate window pointer.     */
  60.     return wnerror(WN_BAD_WIN);
  61.  
  62.     dev = pwin->where_shown.dev;
  63.     if (dev == MONO || dev == COLOR)  /* If it's showing,             */
  64.     {
  65.     if (NIL == wnforget(pwin))    /* abandon border & location.   */
  66.         return b_wnerr;
  67.     }
  68.  
  69.     if (pwin->prev.pdata != NIL)
  70.     {                      /* Free the image of previous   */
  71.                       /* screen data.              */
  72.     free((char *) pwin->prev.pdata);
  73.     pwin->prev.pdata = NIL;
  74.     }
  75.  
  76.     if (pwin->img.pdata != NIL)
  77.     {                      /* Free the memory copy of the  */
  78.                       /* window's data area.          */
  79.     free((char *) pwin->img.pdata);
  80.     pwin->img.pdata = NIL;
  81.     }
  82.  
  83.                       /* Mark the window abandoned.   */
  84.     strcpy(pwin->signature,"Destroyed");
  85.  
  86.     free((char *) pwin);          /* Free the window itself.      */
  87.  
  88.     return WN_NO_ERROR;
  89. }
  90.