home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource4 / 259_01 / win.c < prev    next >
Text File  |  1988-02-25  |  26KB  |  803 lines

  1.  
  2. /***************************************************************************/
  3. /* WIN        - Routines which provide windowing functionality           */
  4. /*                                       */
  5. /*                                       */
  6. /*                                       */
  7. /***************************************************************************/
  8. /*                 Modification Log                   */
  9. /***************************************************************************/
  10. /* Version   Date   Programmer     -----------  Description  --------------- */
  11. /*                                       */
  12. /* V01.00   112787  Bob Withers  Program intially complete.           */
  13. /*                                       */
  14. /*                                       */
  15. /***************************************************************************/
  16.  
  17. #include <stdlib.h>
  18. #include <stddef.h>
  19. #include <string.h>
  20. #include "win.h"
  21.  
  22. #define MAX_WINDOWS           20
  23.  
  24.  
  25. struct sWinData
  26. {
  27.     BYTE        cRow;
  28.     BYTE        cCol;
  29.     BYTE        cWidth;
  30.     BYTE        cHeight;
  31.     BYTE        cWinWidth;
  32.     BYTE        cWinHeight;
  33.     BYTE        cWinClr;
  34.     BYTE        cBdrType;
  35.     BYTE        cBdrClr;
  36.     BYTE        cCurRow;
  37.     BYTE        cCurCol;
  38.     char           *pHidden;
  39.     char        cSaveData[1];
  40. };
  41. typedef struct sWinData WINDATA;
  42. typedef struct sWinData *PWINDATA;
  43.  
  44. static PWINDATA     WinHandle[MAX_WINDOWS + 1];
  45.  
  46.  
  47. /***************************************************************************/
  48. /*  WinCvtHandle    - Convert a window handle into a pointer to the       */
  49. /*              window information data structure.           */
  50. /*  Parms:                                   */
  51. /*    hWnd        - handle to the window                   */
  52. /*                                       */
  53. /*  Return Value:     pointer to WINDATA or NULL if invalid handle       */
  54. /***************************************************************************/
  55.  
  56. static PWINDATA near pascal WinCvtHandle(hWnd)
  57. HWND       hWnd;
  58. {
  59.     if (hWnd < 0 || hWnd > MAX_WINDOWS)
  60.     return(NULL);
  61.     return(WinHandle[hWnd]);
  62. }
  63.  
  64.  
  65. /***************************************************************************/
  66. /*  WinGetHandle    - Return an unused window handle.               */
  67. /*                                       */
  68. /*  Parms:          None                           */
  69. /*                                       */
  70. /*  Return Value:     Window handle or NULL if none available           */
  71. /***************************************************************************/
  72.  
  73. static HWND near pascal WinGetHandle()
  74. {
  75.     register int     i;
  76.  
  77.     for (i = 1; i <= MAX_WINDOWS; ++i)
  78.     {
  79.     if (NULL == WinHandle[i])
  80.         return(i);
  81.     }
  82.     return(NULL);
  83. }
  84.  
  85.  
  86. /***************************************************************************/
  87. /*  WinExplodeWindow - Draws an exploded window on the screen.           */
  88. /*                                       */
  89. /*  Parms:                                   */
  90. /*    nRow        - Top row of requested window (1 relative)           */
  91. /*    nCol        - Left column of requested window (1 relative)       */
  92. /*    nWidth        - Width (in columns) of requested window           */
  93. /*    nHeight        - Height (in rows) of requested window           */
  94. /*    nWinClr        - Color of the window background               */
  95. /*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  96. /*              NO_BOX                       */
  97. /*              DBL_LINE_TOP_BOTTOM                   */
  98. /*              DBL_LINE_SIDES                   */
  99. /*              DBL_LINE_ALL_SIDES                   */
  100. /*              SNGL_LINE_ALL_SIDES                   */
  101. /*              GRAPHIC_BOX                       */
  102. /*              NO_WIND_BORDER                   */
  103. /*    nBdrClr        - Color or the window border               */
  104. /*                                       */
  105. /*  Return Value:     None                           */
  106. /***************************************************************************/
  107.  
  108. void near pascal WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  109.                   nWinClr, nBdrType, nBdrClr)
  110. short       nRow, nCol, nWidth, nHeight;
  111. short       nWinClr, nBdrType, nBdrClr;
  112. {
  113.     register short     nLRR, nLRC, nX1, nY1, nX2, nY2;
  114.  
  115.     nLRR  = nRow + nHeight - 1;
  116.     nLRC  = nCol + nWidth - 1;
  117.     nX1   = (nRow + (nHeight >> 1)) - 1;
  118.     nY1   = (nCol + (nWidth >> 1)) - 3;
  119.     nX2   = nX1 + 2;
  120.     nY2   = nY1 + 5;
  121.     while (TRUE)
  122.     {
  123.     ScrClearRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1, nWinClr);
  124.     ScrDrawRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1,
  125.             nBdrClr, nBdrType);
  126.     if (nX1 == nRow && nY1 == nCol && nX2 == nLRR && nY2 == nLRC)
  127.         break;
  128.     nX1 = (nX1 - 1 < nRow) ? nRow : nX1 - 1;
  129.     nY1 = (nY1 - 3 < nCol) ? nCol : nY1 - 3;
  130.     nX2 = (nX2 + 1 > nLRR) ? nLRR : nX2 + 1;
  131.     nY2 = (nY2 + 3 > nLRC) ? nLRC : nY2 + 3;
  132.     }
  133.     return;
  134. }
  135.  
  136.  
  137.  
  138. /***************************************************************************/
  139. /*  WinDrawWindow    - Draws a window on the screen without creating the   */
  140. /*               WINDATA structure or saving the previous screen       */
  141. /*               contents.                       */
  142. /*                                       */
  143. /*  Parms:                                   */
  144. /*    nRow        - Top row of requested window (1 relative)           */
  145. /*    nCol        - Left column of requested window (1 relative)       */
  146. /*    nWidth        - Width (in columns) of requested window           */
  147. /*    nHeight        - Height (in rows) of requested window           */
  148. /*    nWinClr        - Color of the window background               */
  149. /*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  150. /*              NO_BOX                       */
  151. /*              DBL_LINE_TOP_BOTTOM                   */
  152. /*              DBL_LINE_SIDES                   */
  153. /*              DBL_LINE_ALL_SIDES                   */
  154. /*              SNGL_LINE_ALL_SIDES                   */
  155. /*              GRAPHIC_BOX                       */
  156. /*              NO_WIND_BORDER                   */
  157. /*    nBdrClr        - Color or the window border               */
  158. /*    bExplodeWin   - Boolean value requesting either a pop-up or       */
  159. /*              exploding window                       */
  160. /*              TRUE     ==> Exploding window               */
  161. /*              FALSE  ==> Pop-up window               */
  162. /*                                       */
  163. /*  Return Value:     None                           */
  164. /***************************************************************************/
  165.  
  166. void pascal WinDrawWindow(nRow, nCol, nWidth, nHeight,
  167.               nWinClr, nBdrType, nBdrClr, bExplodeWin)
  168. short       nRow, nCol, nWidth, nHeight;
  169. short       nWinClr, nBdrType, nBdrClr;
  170. short       bExplodeWin;
  171. {
  172.     if (bExplodeWin)
  173.     WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  174.              nWinClr, nBdrType, nBdrClr);
  175.     else
  176.     {
  177.     ScrClearRect(nRow, nCol, nWidth, nHeight, nWinClr);
  178.     ScrDrawRect(nRow, nCol, nWidth, nHeight, nBdrClr, nBdrType);
  179.     }
  180.     return;
  181. }
  182.  
  183.  
  184. /***************************************************************************/
  185. /*  WinCreateWindow - Create a window with the requested attributes and    */
  186. /*              return a handle which may be used to identify this   */
  187. /*              particular window in future calls.           */
  188. /*  Parms:                                   */
  189. /*    nRow        - Top row of requested window (1 relative)           */
  190. /*    nCol        - Left column of requested window (1 relative)       */
  191. /*    nWidth        - Width (in columns) of requested window           */
  192. /*    nHeight        - Height (in rows) of requested window           */
  193. /*    nWinClr        - Color of the window background               */
  194. /*    nBdrType        - Type of border for this window (defined in WIN.H)    */
  195. /*              NO_BOX                       */
  196. /*              DBL_LINE_TOP_BOTTOM                   */
  197. /*              DBL_LINE_SIDES                   */
  198. /*              DBL_LINE_ALL_SIDES                   */
  199. /*              SNGL_LINE_ALL_SIDES                   */
  200. /*              GRAPHIC_BOX                       */
  201. /*              NO_WIND_BORDER                   */
  202. /*    nBdrClr        - Color or the window border               */
  203. /*    bExplodeWin   - Boolean value requesting either a pop-up or       */
  204. /*              exploding window                       */
  205. /*              TRUE     ==> Exploding window               */
  206. /*              FALSE  ==> Pop-up window               */
  207. /*                                       */
  208. /*  Return Value:                               */
  209. /*    hWnd        - Handle of the created window or NULL if an error       */
  210. /*              prevented the creation                   */
  211. /***************************************************************************/
  212.  
  213. HWND pascal WinCreateWindow(nRow, nCol, nWidth, nHeight,
  214.                 nWinClr, nBdrType, nBdrClr, bExplodeWin)
  215. short       nRow, nCol, nWidth, nHeight;
  216. short       nWinClr, nBdrType, nBdrClr;
  217. short       bExplodeWin;
  218. {
  219.     register PWINDATA         pWinData;
  220.     auto     HWND         hWnd;
  221.  
  222.     hWnd = WinGetHandle();
  223.     if (NULL == hWnd)
  224.     return(hWnd);
  225.     pWinData = (PWINDATA) malloc(sizeof(WINDATA)
  226.                    + ScrGetRectSize(nWidth, nHeight));
  227.     if ((PWINDATA) NULL != pWinData)
  228.     {
  229.     WinHandle[hWnd]    = pWinData;
  230.     pWinData->cRow       = (BYTE) nRow;
  231.     pWinData->cCol       = (BYTE) nCol;
  232.     pWinData->cWidth   = pWinData->cWinWidth  = (BYTE) nWidth;
  233.     pWinData->cHeight  = pWinData->cWinH