home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / win100b.zip / wktsmi.c < prev    next >
C/C++ Source or Header  |  1991-10-20  |  4KB  |  160 lines

  1. /*
  2.  * Smart terminal init module
  3.  * 
  4.  * Copyright (c) 1990, 1991 by
  5.  * William S. Hall
  6.  * 3665 Benton Street  #66
  7.  * Santa Clara, CA 95051
  8.  *
  9.  */
  10.  
  11. #define NOCOMM
  12. #define NOKANJI
  13. #define NOSOUND
  14. #define NOATOM
  15. #include <windows.h>
  16. #include <string.h>
  17. #include <ascii.h>
  18. #ifdef COLUMBIA
  19. #include "wktsmt.h"
  20. #else
  21. #include "smterm.h"
  22. #endif
  23.  
  24. static char szSmartTermClass[50];
  25. static int winnum = 0;
  26.  
  27. /* register terminal emulator window */
  28. BOOL NEAR RegisterTermWindow(HANDLE hInstance)
  29. {
  30.  
  31.     WNDCLASS WndClass;
  32.  
  33.     memset((char *)&WndClass, 0, sizeof(WndClass));
  34.  
  35.     WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);  /* standard cursor */
  36.     WndClass.hIcon = NULL;
  37.     WndClass.lpszMenuName = NULL;
  38.     WndClass.lpszClassName = (LPSTR)szSmartTermClass;
  39.     WndClass.hbrBackground = (HBRUSH)NULL;
  40.     WndClass.hInstance = hInstance;
  41.     WndClass.style = CS_VREDRAW | CS_HREDRAW;
  42.     WndClass.lpfnWndProc = SmartTermWndProc;
  43.     WndClass.cbClsExtra = 0;
  44.     WndClass.cbWndExtra = sizeof(PSMT);
  45.  
  46.     return RegisterClass((LPWNDCLASS)&WndClass);
  47.  
  48. }
  49.  
  50. /* create terminal emulation window */
  51. HWND NEAR MakeAndShowTermWindow(HANDLE hInstance, HANDLE hPrevInstance,
  52.                 HWND hPar, PSMT pSmt,
  53.                 DWORD tcolor, DWORD bgcolor,
  54.                 short x, short y, short rows, short cols,
  55.                 BOOL wrap,
  56.                 char *fontface,
  57.                 short nwidth, short nheight, 
  58.                 short swidth, short sheight
  59.                 )
  60. {
  61.  
  62.     GetClassName(hPar, szSmartTermClass, sizeof(szSmartTermClass));
  63.     strcat(szSmartTermClass, "_SmartTerm");
  64.  
  65.     if (!hPrevInstance)
  66.         if (!RegisterTermWindow(hInstance))
  67.             return FALSE;
  68.  
  69.     pSmt->hMain = hPar;
  70.     pSmt->TextColor = tcolor;
  71.     pSmt->BGColor = bgcolor;
  72.     pSmt->MaxCols = cols;
  73.     pSmt->MaxLines = rows;
  74.     pSmt->Wrap = wrap;
  75.     strcpy(pSmt->lfnt.lfFaceName, fontface);
  76.     pSmt->NFontWidth = nwidth;
  77.     pSmt->NFontHeight = nheight;
  78.     pSmt->SFontWidth = swidth;
  79.     pSmt->SFontHeight = sheight;
  80.  
  81.     pSmt->vrect.left = x;
  82.     pSmt->vrect.top = y;
  83.     pSmt->rect.left = pSmt->srect.left = 0;
  84.     pSmt->rect.top = pSmt->srect.top = 0;
  85.  
  86.     if (!(pSmt->hStatic = CreateWindow("STATIC",
  87.                 (LPSTR)NULL,
  88.                     WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
  89.                     pSmt->vrect.left,
  90.                 pSmt->vrect.top,
  91.                 0,0,
  92.                     hPar,
  93.                 winnum++,
  94.                     (HANDLE)hInstance,
  95.                     (LPSTR)NULL)))
  96.     return FALSE;
  97.  
  98.     pSmt->hWnd = CreateWindow(szSmartTermClass,
  99.                      (LPSTR)NULL,
  100.                  WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS,
  101.                  pSmt->rect.left,
  102.                  pSmt->rect.top,
  103.                  0,0,
  104.                  pSmt->hStatic,
  105.                  winnum++,
  106.                  (HANDLE)hInstance,
  107.                  (LPSTR)pSmt);
  108.  
  109.     if (pSmt->hWnd && pSmt->pVidBuffer)
  110.     return (pSmt->hWnd);
  111.  
  112.     return 0;
  113.  
  114. }
  115.            
  116. void SmartTermWndCreate(HWND hWnd, LONG lParam)
  117. {
  118.  
  119.     LPCREATESTRUCT pCS;
  120.     PSMT pSmt;
  121.     register int i,j;
  122.  
  123.     pCS = (LPCREATESTRUCT)lParam;
  124.     pSmt = (PSMT)LOWORD(pCS->lpCreateParams);
  125.     SetWindowWord(hWnd,0,(WORD)pSmt);
  126.  
  127.     pSmt->hFont = SetFontData(pSmt);
  128.     pSmt->hbr = CreateSolidBrush(pSmt->BGColor);
  129.  
  130.     pSmt->srect.right = pSmt->rect.right = pSmt->CharWidth * pSmt->MaxCols;
  131.     pSmt->srect.bottom = pSmt->rect.bottom = pSmt->CharHeight * pSmt->MaxLines;
  132.  
  133.     pSmt->BufSize = MAXTEXTBUFFERS * pSmt->MaxLines * MAXCOLUMNS;
  134.     pSmt->pVidBuffer = (WORD *)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT,
  135.                       pSmt->BufSize * sizeof(WORD));
  136.  
  137.     if (pSmt->pVidBuffer) {
  138.         pSmt->MaxTextLines = MAXTEXTBUFFERS * pSmt->MaxLines;
  139.     for (i = 0; i < pSmt->MaxTextLines; i++) {
  140.         pSmt->lines[i] = (pSmt->pVidBuffer + i * MAXCOLUMNS);
  141.         for (j = 0; j < MAXCOLUMNS; j++)
  142.         *(pSmt->lines[i] + j) = SP;
  143.     }
  144.     pSmt->MaxScrollBack = pSmt->MaxTextLines - pSmt->MaxLines;
  145.  
  146.     pSmt->TopScroll = pSmt->TopOrgLine = 0;
  147.     pSmt->BottomScroll = pSmt->BottomOrgLine = pSmt->MaxLines - 1;
  148.     pSmt->CurLine = 0;
  149.     pSmt->CurLineOffset = 0;
  150.     pSmt->Pos.x = pSmt->Pos.y = 0;
  151.     for (i = 0; i < MAXCOLUMNS; i++) {
  152.         if ((i > 0) && ((i % 8) == 0))
  153.         pSmt->TabStops[i] = 'T';
  154.         else
  155.         pSmt->TabStops[i] = SP;
  156.     }
  157.     }               
  158. }
  159.  
  160.