home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 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->cWinHeight = (BYTE) nHeight;
  234.     pWinData->cWinClr  = (BYTE) nWinClr;
  235.     pWinData->cBdrType = (BYTE) nBdrType;
  236.     pWinData->cBdrClr  = (BYTE) nBdrClr;
  237.     pWinData->cCurRow  = pWinData->cCurCol = (BYTE) 1;
  238.     pWinData->pHidden  = NULL;
  239.     if (NO_WIND_BORDER != nBdrType)
  240.     {
  241.         pWinData->cWinWidth  -= 2;
  242.         pWinData->cWinHeight -= 2;
  243.     }
  244.     ScrSaveRect(nRow, nCol, nWidth, nHeight, pWinData->cSaveData);
  245.     if (bExplodeWin)
  246.         WinExplodeWindow(nRow, nCol, nWidth, nHeight,
  247.                  nWinClr, nBdrType, nBdrClr);
  248.     else
  249.     {
  250.         ScrClearRect(nRow, nCol, nWidth, nHeight, nWinClr);
  251.         ScrDrawRect(nRow, nCol, nWidth, nHeight, nBdrClr, nBdrType);
  252.     }
  253.     WinSetCursorPos((HWND) pWinData, 1, 1);
  254.     }
  255.     return(hWnd);
  256. }
  257.  
  258.  
  259. /***************************************************************************/
  260. /*  WinDestoryWindow - Destroy the window represented by hWnd and replace  */
  261. /*               the previous screen contents saved when the window  */
  262. /*               was created.                       */
  263. /*  Parms:                                   */
  264. /*    hWnd        - Handle to the window to be destroyed           */
  265. /*                                       */
  266. /*  Return Value:     TRUE => window destroyed, FALSE => invalid handle    */
  267. /***************************************************************************/
  268.  
  269. BOOL pascal WinDestroyWindow(hWnd)
  270. HWND       hWnd;
  271. {
  272.     register PWINDATA        pWinData;
  273.  
  274.     pWinData = WinCvtHandle(hWnd);
  275.     if (NULL == pWinData)
  276.     return(FALSE);
  277.     ScrRestoreRect(pWinData->cRow, pWinData->cCol, pWinData->cWidth,
  278.            pWinData->cHeight, pWinData->cSaveData);
  279.     if (NULL != pWinData->pHidden)
  280.     free(pWinData->pHidden);
  281.     free((char *) pWinData);
  282.     WinHandle[hWnd] = NULL;
  283.     return(TRUE);
  284. }
  285.  
  286.  
  287. /***************************************************************************/
  288. /*  WinScrollWindowUp  - Scrolls the requested window up one line.       */
  289. /*                                       */
  290. /*  Parms:                                   */
  291. /*    hWnd        - Handle to the window to be scrolled           */
  292. /*                                       */
  293. /*  Return Value:     None                           */
  294. /***************************************************************************/
  295.  
  296. void pascal WinScrollWindowUp(hWnd)
  297. HWND         hWnd;
  298. {
  299.     register PWINDATA        pWinData;
  300.     auto     short        nRow, nCol;
  301.  
  302.     pWinData = WinCvtHandle(hWnd);
  303.     if (NULL == pWinData)
  304.     return;
  305.     if (NULL == pWinData->pHidden)
  306.     {
  307.     nRow = pWinData->cRow;
  308.     nCol = pWinData->cCol;
  309.     if (NO_WIND_BORDER != pWinData->cBdrType)
  310.     {
  311.         nRow++;
  312.         nCol++;
  313.     }
  314.     ScrScrollRectUp(nRow, nCol, pWinData->cWinWidth,
  315.             pWinData->cWinHeight, 1, pWinData->cWinClr);
  316.     }
  317.     return;
  318. }
  319.  
  320.  
  321. /***************************************************************************/
  322. /*  WinScrollWindowDown - Scrolls the requested window down one line.       */
  323. /*                                       */
  324. /*  Parms:                                   */
  325. /*    hWnd        - Handle to the window to be scrolled           */
  326. /*                                       */
  327. /*  Return Value:     None                           */
  328. /***************************************************************************/
  329.  
  330. void pascal WinScrollWindowDown(hWnd)
  331. HWND         hWnd;
  332. {
  333.     register PWINDATA        pWinData;
  334.     auto     short        nRow, nCol;
  335.  
  336.     pWinData = WinCvtHandle(hWnd);
  337.     if (NULL == pWinData)
  338.     return;
  339.     if (NULL == pWinData->pHidden)
  340.     {
  341.     nRow = pWinData->cRow;
  342.     nCol = pWinData->cCol;
  343.     if (NO_WIND_BORDER != pWinData->cBdrType)
  344.     {
  345.         nRow++;
  346.         nCol++;
  347.     }
  348.     ScrScrollRectDown(nRow, nCol, pWinData->cWinWidth,
  349.               pWinData->cWinHeight, 1, pWinData->cWinClr);
  350.     }
  351.     return;
  352. }
  353.  
  354.  
  355. /***************************************************************************/
  356. /*  WinSetCursorPos - Position the cursor relative to the selected window. */
  357. /*              The upper left hand corner of the window is (1,1)    */
  358. /*                                       */
  359. /*  Parms:                                   */
  360. /*    hWnd        - Handle to the window to position the cusor in       */
  361. /*    nRow        - Row to position cursor to within window (1 relative) */
  362. /*    nCol        - Col to position cursor to within window (1 relative) */
  363. /*                                       */
  364. /*  Return Value:     None                           */
  365. /***************************************************************************/
  366.  
  367. void pascal WinSetCursorPos(hWnd, nRow, nCol)
  368. HWND        hWnd;
  369. short        nRow, nCol;
  370. {
  371.     register PWINDATA        pWinData;
  372.     auto     short        nMaxRow, nMaxCol;
  373.  
  374.     if (NULL == hWnd)
  375.     {
  376.     ScrSetCursorPos(nRow, nCol);
  377.     return;
  378.     }
  379.     pWinData = WinCvtHandle(hWnd);
  380.     if (NULL == pWinData)
  381.     return;
  382.     if (nRow > pWinData->cWinHeight && nCol > pWinData->cWinWidth)
  383.     return;
  384.     pWinData->cCurRow = (BYTE) nRow;
  385.     pWinData->cCurCol = (BYTE) nCol;
  386.     nRow = nRow + pWinData->cRow - 1;
  387.     nCol = nCol + pWinData->cCol - 1;
  388.     if (NO_WIND_BORDER != pWinData->cBdrType)
  389.     {
  390.     ++nRow;
  391.     ++nCol;
  392.     }
  393.     ScrSetCursorPos(nRow, nCol);
  394.     return;
  395. }
  396.  
  397.  
  398. /***************************************************************************/
  399. /*  WinClearScreen - Clear a window to the desired color.           */
  400. /*                                       */
  401. /*  Parms:                                   */
  402. /*    hWnd       - Handle to the window to be cleared            */
  403. /*             (A handle of NULL clears the entire screen)       */
  404. /*    nColor       - Color to be used in clearing the window           */
  405. /*                                       */
  406. /*  Return Value:    None                           */
  407. /***************************************************************************/
  408.  
  409. void pascal WinClearScreen(hWnd, nColor)
  410. HWND        hWnd;
  411. short        nColor;
  412. {
  413.     register PWINDATA        pWinData;
  414.     auto     short        nRow, nCol;
  415.  
  416.     if (NULL == hWnd)
  417.     ScrClearRect(1, 1, 80, 25, nColor);
  418.     else
  419.     {
  420.     pWinData = WinCvtHandle(hWnd);
  421.     if (NULL == pWinData)
  422.         return;
  423.     nRow     = pWinData->cRow;
  424.     nCol     = pWinData->cCol;
  425.     if (NO_WIND_BORDER != pWinData->cBdrType)
  426.     {
  427.         ++nRow;
  428.         ++nCol;
  429.     }
  430.     pWinData->cWinClr = (BYTE) nColor;
  431.     ScrClearRect(nRow, nCol, pWinData->cWinWidth, pWinData->cWinHeight,
  432.              pWinData->cWinClr);
  433.     }
  434.     return;
  435. }
  436.  
  437.  
  438. /***************************************************************************/
  439. /*  WinTextOut       - Display a string to the requested window at the       */
  440. /*             current cursor location (for that window) using the   */
  441. /*             passed color attribute.                   */
  442. /*             If the string extends beyond the boundries of the       */
  443. /*             window it will be truncated.               */
  444. /*  Parms:                                   */
  445. /*    hWnd       - Handle of the window                   */
  446. /*    pStr       - Pointer to the NULL terminated string to display       */
  447. /*    nAttr       - Color attribute to be used in displaying the string   */
  448. /*                                       */
  449. /*  Return Value:    None                           */
  450. /***************************************************************************/
  451.  
  452. void pascal WinTextOut(hWnd, pStr, nAttr)
  453. HWND        hWnd;
  454. char       *pStr;
  455. short        nAttr;
  456. {
  457.     register PWINDATA    pWinData;
  458.     auto     short    nCount;
  459.     auto     short    nRow, nCol;
  460.  
  461.     pWinData = WinCvtHandle(hWnd);
  462.     if (NULL == pWinData)
  463.     return;
  464.     ScrGetCursorPos(&nRow, &nCol);
  465.     WinSetCursorPos(hWnd, pWinData->cCurRow, pWinData->cCurCol);
  466.     nCount = pWinData->cWinWidth - pWinData->cCurCol + 1;
  467.     ScrTextOut(pStr, nAttr, nCount);
  468.     ScrSetCursorPos(nRow, nCol);
  469.     return;
  470. }
  471.  
  472.  
  473. /***************************************************************************/
  474. /*  WinCenterText  - Centers a text string in a window.            */
  475. /*                                       */
  476. /*  Parms:                                   */
  477. /*    hWnd       - Handle of the window                   */
  478. /*    nRow       - Window row to place the string on               */
  479. /*    pStr       - Pointer to the string to be displayed           */
  480. /*    nColor       - Color attribute used to display the string        */
  481. /*                                       */
  482. /*  Return Value:    None                           */
  483. /***************************************************************************/
  484. void pascal WinCenterText(hWnd, nRow, pStr, nColor)
  485. HWND        hWnd;
  486. short        nRow;
  487. char       *pStr;
  488. short        nColor;
  489. {
  490.     if (NULL == WinCvtHandle(hWnd))
  491.     return;
  492.     WinSetCursorPos(hWnd, nRow, (WinGetWindowWidth(hWnd) - strlen(pStr)) / 2);
  493.     WinTextOut(hWnd, pStr, nColor);
  494.     return;
  495. }
  496.  
  497.  
  498. /***************************************************************************/
  499. /*  WinMoveWindow  - Move an existing window to a new screen location.       */
  500. /*             In this version the window to be moved MUST be fully  */
  501. /*             visible on the screen for WinMoveWindow to perform    */
  502. /*             properly.    If the window being moved is completely or */
  503. /*             partially under another window the screen will not    */
  504. /*             be left in the correct state (i.e. garbage on screen).*/
  505. /*             It is the callers responsibility to insure that the   */
  506. /*             window is not being moved off the screen.    Even with  */
  507. /*             these restriction this can be a handy routine and is  */
  508. /*             included for that reason.    A future release of the    */
  509. /*             package may fix these shortcomings.           */
  510. /*                                       */
  511. /*  Parms:                                   */
  512. /*    hWnd       - Handle to the window to be moved               */
  513. /*    nRow       - Move the window to this row               */
  514. /*    nCol       - Move the window to this column               */
  515. /*                                       */
  516. /*  Return Value:    None                           */
  517. /***************************************************************************/
  518.  
  519. void pascal WinMoveWindow(hWnd, nRow, nCol)
  520. HWND        hWnd;
  521. short        nRow, nCol;
  522. {
  523.     register PWINDATA        pWinData;
  524.     register char       *pBuf;
  525.  
  526.     pWinData = WinCvtHandle(hWnd);
  527.     if (NULL == pWinData)
  528.     return;
  529.     if (NULL != pWinData->pHidden)
  530.     {
  531.     pWinData->cRow = (BYTE) nRow;
  532.     pWinData->cCol = (BYTE) nCol;
  533.     return;
  534.     }
  535.     pBuf     = malloc(ScrGetRectSize(pWinData->cWidth, pWinData->cHeight));
  536.     if (NULL != pBuf)
  537.     {
  538.     ScrSaveRect(pWinData->cRow, pWinData->cCol,
  539.             pWinData->cWidth, pWinData->cHeight, pBuf);
  540.     ScrRestoreRect(pWinData->cRow, pWinData->cCol,
  541.                pWinData->cWidth, pWinData->cHeight,
  542.                pWinData->cSaveData);
  543.     ScrSaveRect(nRow, nCol, pWinData->cWidth, pWinData->cHeight,
  544.             pWinData->cSaveData);
  545.     ScrRestoreRect(nRow, nCol, pWinData->cWidth, pWinData->cHeight, pBuf);
  546.     pWinData->cRow = (BYTE) nRow;
  547.     pWinData->cCol = (BYTE) nCol;
  548.     free(pBuf);
  549.     }
  550.     return;
  551. }
  552.  
  553.  
  554. /***************************************************************************/
  555. /*  WinGetWindowRow - Returns the row value currently associated with the  */
  556. /*              passed window handle.                   */
  557. /*  Parms:                                   */
  558. /*    hWnd       - Handle to the window                   */
  559. /*                                       */
  560. /*  Return Value:    Row the window currently resides at           */
  561. /***************************************************************************/
  562.  
  563. short pascal WinGetWindowRow(hWnd)
  564. HWND        hWnd;
  565. {
  566.     register PWINDATA       pWinData;
  567.  
  568.     pWinData = WinCvtHandle(hWnd);
  569.     if (NULL == pWinData)
  570.     return(0);
  571.     return(pWinData->cRow);
  572. }
  573.  
  574.  
  575. /***************************************************************************/
  576. /*  WinGetWindowCol - Returns the col value currently associated with the  */
  577. /*              passed window handle.                   */
  578. /*  Parms:                                   */
  579. /*    hWnd       - Handle to the window                   */
  580. /*                                       */
  581. /*  Return Value:    Column the window currently resides at           */
  582. /***************************************************************************/
  583.  
  584. short pascal WinGetWindowCol(hWnd)
  585. HWND        hWnd;
  586. {
  587.     register PWINDATA        pWinData;
  588.  
  589.     pWinData = WinCvtHandle(hWnd);
  590.     if (NULL == pWinData)
  591.     return(0);
  592.     return(pWinData->cCol);
  593. }
  594.  
  595.  
  596. /***************************************************************************/
  597. /*  WinGetWindowWidth - Returns the column width of the passed window.       */
  598. /*                                       */
  599. /*  Parms:                                   */
  600. /*    hWnd       - Handle to the window                   */
  601. /*                                       */
  602. /*  Return Value:    Number of columns in the window               */
  603. /***************************************************************************/
  604.  
  605. short pascal WinGetWindowWidth(hWnd)
  606. HWND        hWnd;
  607. {
  608.     register PWINDATA       pWinData;
  609.  
  610.     pWinData = WinCvtHandle(hWnd);
  611.     if (NULL == pWinData)
  612.     return(0);
  613.     return(pWinData->cWinWidth);
  614. }
  615.  
  616.  
  617. /***************************************************************************/
  618. /*  WinGetWindowHeight - Returns the number of rows in the passed window.  */
  619. /*                                       */
  620. /*  Parms:                                   */
  621. /*    hWnd       - Handle to the window                   */
  622. /*                                       */
  623. /*  Return Value:    Number of rows in the window               */
  624. /***************************************************************************/
  625.  
  626. short pascal WinGetWindowHeight(hWnd)
  627. HWND        hWnd;
  628. {
  629.     register PWINDATA        pWinData;
  630.  
  631.     pWinData = WinCvtHandle(hWnd);
  632.     if (NULL == pWinData)
  633.     return(0);
  634.     return(pWinData->cWinHeight);
  635. }
  636.  
  637.  
  638. /***************************************************************************/
  639. /*  WinGetWindowClr - Get the window background color               */
  640. /*                                       */
  641. /*  Parms:                                   */
  642. /*    hWnd       - Handle to the window                   */
  643. /*                                       */
  644. /*  Return Value:    Returns the attribute for the window color        */
  645. /***************************************************************************/
  646.  
  647. short pascal WinGetWindowClr(hWnd)
  648. HWND        hWnd;
  649. {
  650.     register PWINDATA        pWinData;
  651.  
  652.     pWinData = WinCvtHandle(hWnd);
  653.     if (NULL == pWinData)
  654.     return(0);
  655.     return(pWinData->cWinClr);
  656. }
  657.  
  658.  
  659. /***************************************************************************/
  660. /*  WinGetWindowBdrClr - Get the window border color               */
  661. /*                                       */
  662. /*  Parms:                                   */
  663. /*    hWnd       - Handle to the window                   */
  664. /*                                       */
  665. /*  Return Value:    Returns the attribute for the window border color       */
  666. /***************************************************************************/
  667.  
  668. short pascal WinGetWindowBdrClr(hWnd)
  669. HWND        hWnd;
  670. {
  671.     register PWINDATA        pWinData;
  672.  
  673.     pWinData = WinCvtHandle(hWnd);
  674.     if (NULL == pWinData)
  675.     return(0);
  676.     return(pWinData->cBdrClr);
  677. }
  678.  
  679.  
  680. /***************************************************************************/
  681. /*  WinGetBorderType - Gets the border type of the passed window       */
  682. /*                                       */
  683. /*  Parms:                                   */
  684. /*    hWnd       - Handle to the window                   */
  685. /*                                       */
  686. /*  Return Value:    Returns the window border type               */
  687. /***************************************************************************/
  688.  
  689. short pascal WinGetBorderType(hWnd)
  690. HWND        hWnd;
  691. {
  692.     register PWINDATA        pWinData;
  693.  
  694.     pWinData = WinCvtHandle(hWnd);
  695.     if (NULL == pWinData)
  696.     return(0);
  697.     return(pWinData->cBdrType);
  698. }
  699.  
  700.  
  701. /***************************************************************************/
  702. /*  WinHideWindow  - Removes a window from the screen, saving it's         */
  703. /*             contents.    The window can later be placed back on       */
  704. /*             the screen via WinShowWindow().  Note that in this    */
  705. /*             release the window MUST be fully visible for this       */
  706. /*             operating to work correctly.               */
  707. /*  Parms:                                   */
  708. /*    hWnd       - Handle to the window                   */
  709. /*                                       */
  710. /*  Return Value:    TRUE => window hidden, FALSE => buf alloc failed       */
  711. /***************************************************************************/
  712.  
  713. BOOL pascal WinHideWindow(hWnd)
  714. HWND        hWnd;
  715. {
  716.     register PWINDATA       pWinData;
  717.     auto     char      *pBuf;
  718.     auto     short       nBufSize;
  719.     auto     short       nRow, nCol, nWidth, nHeight;
  720.  
  721.     pWinData = WinCvtHandle(hWnd);
  722.     if (NULL == pWinData)
  723.     return(FALSE);
  724.     nRow     = pWinData->cRow;
  725.     nCol     = pWinData->cCol;
  726.     nWidth   = pWinData->cWidth;
  727.     nHeight  = pWinData->cHeight;
  728.     nBufSize = ScrGetRectSize(nWidth, nHeight);
  729.     if (NULL != pWinData->pHidden)
  730.     free(pWinData->pHidden);
  731.     pBuf     = malloc(nBufSize);
  732.     if (NULL == pBuf)
  733.     return(FALSE);
  734.     ScrSaveRect(nRow, nCol, nWidth, nHeight, pBuf);
  735.     ScrRestoreRect(nRow, nCol, nWidth, nHeight, pWinData->cSaveData);
  736.     pWinData->pHidden = pBuf;
  737.     return(TRUE);
  738. }
  739.  
  740.  
  741. /***************************************************************************/
  742. /*  WinShowWindow  - Places a hidden window back on the screen and frees   */
  743. /*             the buffer used to hold the window image.           */
  744. /*  Parms:                                   */
  745. /*    hWnd       - Handle to the window                   */
  746. /*                                       */
  747. /*  Return Value:    TRUE => window shown, FALSE => window wasn't hidden   */
  748. /***************************************************************************/
  749.  
  750. BOOL pascal WinShowWindow(hWnd)
  751. HWND         hWnd;
  752. {
  753.     register PWINDATA        pWinData;
  754.  
  755.     pWinData = WinCvtHandle(hWnd);
  756.     if (NULL == pWinData)
  757.     return(FALSE);
  758.     if (NULL == pWinData->pHidden)
  759.     return(FALSE);
  760.     ScrRestoreRect(pWinData->cRow, pWinData->cCol, pWinData->cWidth,
  761.            pWinData->cHeight, pWinData->pHidden);
  762.     free(pWinData->pHidden);
  763.     pWinData->pHidden = NULL;
  764.     return(TRUE);
  765. }
  766.  
  767.  
  768. /***************************************************************************/
  769. /*  WinInitialize  - Init the windowing system.                */
  770. /*                                       */
  771. /*  Parms:         None                           */
  772. /*                                       */
  773. /*  Return Value:    None                           */
  774. /***************************************************************************/
  775.  
  776. void pascal WinInitialize()
  777. {
  778.     ScrInitialize();
  779.     memset((char *) WinHandle, NULL, sizeof(WinHandle));
  780.     return;
  781. }
  782.  
  783.  
  784. /***************************************************************************/
  785. /*  WinTerminate   - Clean up the windowing package               */
  786. /*                                       */
  787. /*  Parms:         None                           */
  788. /*                                       */
  789. /*  Return Value:    None                           */
  790. /***************************************************************************/
  791.  
  792. void pascal WinTerminate()
  793. {
  794.     register short     i;
  795.  
  796.     for (i = 1; i <= MAX_WINDOWS; ++i)
  797.     {
  798.     if (WinHandle[i] != NULL)
  799.         WinDestroyWindow(i);
  800.     }
  801.     return;
  802. }
  803.