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 >
Wrap
Text File
|
1988-02-25
|
26KB
|
803 lines
/***************************************************************************/
/* WIN - Routines which provide windowing functionality */
/* */
/* */
/* */
/***************************************************************************/
/* Modification Log */
/***************************************************************************/
/* Version Date Programmer ----------- Description --------------- */
/* */
/* V01.00 112787 Bob Withers Program intially complete. */
/* */
/* */
/***************************************************************************/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "win.h"
#define MAX_WINDOWS 20
struct sWinData
{
BYTE cRow;
BYTE cCol;
BYTE cWidth;
BYTE cHeight;
BYTE cWinWidth;
BYTE cWinHeight;
BYTE cWinClr;
BYTE cBdrType;
BYTE cBdrClr;
BYTE cCurRow;
BYTE cCurCol;
char *pHidden;
char cSaveData[1];
};
typedef struct sWinData WINDATA;
typedef struct sWinData *PWINDATA;
static PWINDATA WinHandle[MAX_WINDOWS + 1];
/***************************************************************************/
/* WinCvtHandle - Convert a window handle into a pointer to the */
/* window information data structure. */
/* Parms: */
/* hWnd - handle to the window */
/* */
/* Return Value: pointer to WINDATA or NULL if invalid handle */
/***************************************************************************/
static PWINDATA near pascal WinCvtHandle(hWnd)
HWND hWnd;
{
if (hWnd < 0 || hWnd > MAX_WINDOWS)
return(NULL);
return(WinHandle[hWnd]);
}
/***************************************************************************/
/* WinGetHandle - Return an unused window handle. */
/* */
/* Parms: None */
/* */
/* Return Value: Window handle or NULL if none available */
/***************************************************************************/
static HWND near pascal WinGetHandle()
{
register int i;
for (i = 1; i <= MAX_WINDOWS; ++i)
{
if (NULL == WinHandle[i])
return(i);
}
return(NULL);
}
/***************************************************************************/
/* WinExplodeWindow - Draws an exploded window on the screen. */
/* */
/* Parms: */
/* nRow - Top row of requested window (1 relative) */
/* nCol - Left column of requested window (1 relative) */
/* nWidth - Width (in columns) of requested window */
/* nHeight - Height (in rows) of requested window */
/* nWinClr - Color of the window background */
/* nBdrType - Type of border for this window (defined in WIN.H) */
/* NO_BOX */
/* DBL_LINE_TOP_BOTTOM */
/* DBL_LINE_SIDES */
/* DBL_LINE_ALL_SIDES */
/* SNGL_LINE_ALL_SIDES */
/* GRAPHIC_BOX */
/* NO_WIND_BORDER */
/* nBdrClr - Color or the window border */
/* */
/* Return Value: None */
/***************************************************************************/
void near pascal WinExplodeWindow(nRow, nCol, nWidth, nHeight,
nWinClr, nBdrType, nBdrClr)
short nRow, nCol, nWidth, nHeight;
short nWinClr, nBdrType, nBdrClr;
{
register short nLRR, nLRC, nX1, nY1, nX2, nY2;
nLRR = nRow + nHeight - 1;
nLRC = nCol + nWidth - 1;
nX1 = (nRow + (nHeight >> 1)) - 1;
nY1 = (nCol + (nWidth >> 1)) - 3;
nX2 = nX1 + 2;
nY2 = nY1 + 5;
while (TRUE)
{
ScrClearRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1, nWinClr);
ScrDrawRect(nX1, nY1, nY2 - nY1 + 1, nX2 - nX1 + 1,
nBdrClr, nBdrType);
if (nX1 == nRow && nY1 == nCol && nX2 == nLRR && nY2 == nLRC)
break;
nX1 = (nX1 - 1 < nRow) ? nRow : nX1 - 1;
nY1 = (nY1 - 3 < nCol) ? nCol : nY1 - 3;
nX2 = (nX2 + 1 > nLRR) ? nLRR : nX2 + 1;
nY2 = (nY2 + 3 > nLRC) ? nLRC : nY2 + 3;
}
return;
}
/***************************************************************************/
/* WinDrawWindow - Draws a window on the screen without creating the */
/* WINDATA structure or saving the previous screen */
/* contents. */
/* */
/* Parms: */
/* nRow - Top row of requested window (1 relative) */
/* nCol - Left column of requested window (1 relative) */
/* nWidth - Width (in columns) of requested window */
/* nHeight - Height (in rows) of requested window */
/* nWinClr - Color of the window background */
/* nBdrType - Type of border for this window (defined in WIN.H) */
/* NO_BOX */
/* DBL_LINE_TOP_BOTTOM */
/* DBL_LINE_SIDES */
/* DBL_LINE_ALL_SIDES */
/* SNGL_LINE_ALL_SIDES */
/* GRAPHIC_BOX */
/* NO_WIND_BORDER */
/* nBdrClr - Color or the window border */
/* bExplodeWin - Boolean value requesting either a pop-up or */
/* exploding window */
/* TRUE ==> Exploding window */
/* FALSE ==> Pop-up window */
/* */
/* Return Value: None */
/***************************************************************************/
void pascal WinDrawWindow(nRow, nCol, nWidth, nHeight,
nWinClr, nBdrType, nBdrClr, bExplodeWin)
short nRow, nCol, nWidth, nHeight;
short nWinClr, nBdrType, nBdrClr;
short bExplodeWin;
{
if (bExplodeWin)
WinExplodeWindow(nRow, nCol, nWidth, nHeight,
nWinClr, nBdrType, nBdrClr);
else
{
ScrClearRect(nRow, nCol, nWidth, nHeight, nWinClr);
ScrDrawRect(nRow, nCol, nWidth, nHeight, nBdrClr, nBdrType);
}
return;
}
/***************************************************************************/
/* WinCreateWindow - Create a window with the requested attributes and */
/* return a handle which may be used to identify this */
/* particular window in future calls. */
/* Parms: */
/* nRow - Top row of requested window (1 relative) */
/* nCol - Left column of requested window (1 relative) */
/* nWidth - Width (in columns) of requested window */
/* nHeight - Height (in rows) of requested window */
/* nWinClr - Color of the window background */
/* nBdrType - Type of border for this window (defined in WIN.H) */
/* NO_BOX */
/* DBL_LINE_TOP_BOTTOM */
/* DBL_LINE_SIDES */
/* DBL_LINE_ALL_SIDES */
/* SNGL_LINE_ALL_SIDES */
/* GRAPHIC_BOX */
/* NO_WIND_BORDER */
/* nBdrClr - Color or the window border */
/* bExplodeWin - Boolean value requesting either a pop-up or */
/* exploding window */
/* TRUE ==> Exploding window */
/* FALSE ==> Pop-up window */
/* */
/* Return Value: */
/* hWnd - Handle of the created window or NULL if an error */
/* prevented the creation */
/***************************************************************************/
HWND pascal WinCreateWindow(nRow, nCol, nWidth, nHeight,
nWinClr, nBdrType, nBdrClr, bExplodeWin)
short nRow, nCol, nWidth, nHeight;
short nWinClr, nBdrType, nBdrClr;
short bExplodeWin;
{
register PWINDATA pWinData;
auto HWND hWnd;
hWnd = WinGetHandle();
if (NULL == hWnd)
return(hWnd);
pWinData = (PWINDATA) malloc(sizeof(WINDATA)
+ ScrGetRectSize(nWidth, nHeight));
if ((PWINDATA) NULL != pWinData)
{
WinHandle[hWnd] = pWinData;
pWinData->cRow = (BYTE) nRow;
pWinData->cCol = (BYTE) nCol;
pWinData->cWidth = pWinData->cWinWidth = (BYTE) nWidth;
pWinData->cHeight = pWinData->cWinH