home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winkerm.zip / WINWND.C < prev   
C/C++ Source or Header  |  1986-10-10  |  7KB  |  263 lines

  1.  
  2. /***************************************************************************
  3. *
  4. * Winwnd
  5. *
  6. * Kermit window procedure and support modules.
  7. *
  8. ***************************************************************************/
  9.      
  10. #include <windows.h>
  11. #include "winkrm.h"
  12.      
  13. void NEAR KermPaint(HDC, RECT);
  14.      
  15. /***************************************************************************
  16. *
  17. * WinKermWndProc
  18. *
  19. * Kermit window proceedure
  20. *
  21. ***************************************************************************/
  22. LONG FAR PASCAL WinKermWndProc(hWnd,message,wParam,lParam)
  23. HWND hWnd;
  24. unsigned message;
  25. WORD wParam;
  26. LONG lParam;
  27. {
  28.     PAINTSTRUCT ps;
  29.     int result;
  30.      
  31. /* handle messages for main, tiled window */
  32.     if (hWnd == hKermWnd) {
  33.         switch (message) {
  34.      
  35.         case WM_COMMAND:
  36.             KerCommand(hWnd,wParam,lParam);
  37.             break;
  38.      
  39.         case WM_SIZE:
  40.             ReleaseDC(hKermWnd, hKermDC);
  41.             if (!(( lParam == 0) && (wParam == SIZENORMAL))) {
  42.             ScreenLineLen =  (LOWORD(lParam)) / CharWidth;
  43.             XClientSize = ScreenLineLen * CharWidth;
  44.             CurrentMaxLine = (HIWORD(lParam)) / CharHeight;
  45.             YClientSize = CurrentMaxLine * CharHeight;
  46.             CurrentMaxLine = CurrentMaxLine * (MaxCharLineLen+2);
  47.             MaxLinesOnScreen = CurrentMaxLine / LineIncrement;
  48.                 }
  49.             hKermDC = GetDC(hKermWnd);
  50.             break;
  51.      
  52.         case WM_SYSCOMMAND:
  53.             if (wParam == APPABOUT)
  54.             DialogBox(hInst,MAKEINTRESOURCE(ABOUTBOX),hWnd,lpprocAbout);
  55.             else
  56.                 return(DefWindowProc(hWnd,message,wParam,lParam));
  57.             break;
  58.      
  59.         case WM_CLOSE:
  60.             result = MessageBox(hKermWnd,
  61.                       (LPSTR)"Terminate Kermit",
  62.                     (LPSTR)szWinTitle,
  63.                     MB_OKCANCEL | MB_ICONQUESTION);
  64.             if (result == IDOK) {
  65.             if (cid >= 0)
  66.                 CloseComm(cid);
  67.      
  68. /*
  69.  * free public and private resources, free scratch files, reset baud
  70.  * rates, free memory, screen space, and brushes
  71. */
  72.      
  73.             DestroyWindow(hKermWnd);
  74.             }
  75.             break;
  76.      
  77.         case WM_QUERYENDSESSION:
  78.             result = MessageBox(hKermWnd,
  79.                     (LPSTR)"Terminate Kermit",
  80.                     (LPSTR)szWinTitle,
  81.                     MB_OKCANCEL | MB_ICONQUESTION);
  82.             if (result == IDOK)
  83.             return (TRUE);
  84.             return (FALSE);
  85.             break;
  86.      
  87.         case WM_ENDSESSION:
  88.             if (wParam == TRUE) {
  89.             if (cid >= 0)
  90.                 CloseComm(cid);
  91. /*
  92.  * free public and private resources, free scratch files, reset baud
  93.  * rates, free memory, screen space, and brushes
  94. */
  95.             return(TRUE);
  96.             }
  97.             break;
  98.      
  99.         case WM_CHAR:
  100.             if (cid >= 0)
  101.             if (CurrentState == CONNECTSTATE) {
  102.                 static ShortStr[2] = {0,0};
  103.                 ShortStr[0] = wParam;
  104.                 WriteComm(cid, (LPSTR)ShortStr,1);
  105.                 }
  106.             break;
  107.      
  108.         case WM_SETFOCUS:
  109.             CreateCaret(hWnd, (HBITMAP)NULL, 0, (int)CharHeight);
  110.             SetCaretPos(Xpos, Ypos);
  111.             ShowCaret(hWnd);
  112.             break;
  113.      
  114.         case WM_KILLFOCUS:
  115.             HideCaret(hWnd);
  116.             DestroyCaret();
  117.             break;
  118.      
  119.         case WM_DESTROY:
  120.             PostQuitMessage(0);
  121.             break;
  122.      
  123.         case WM_PAINT:
  124.             BeginPaint(hWnd,(LPPAINTSTRUCT)&ps);
  125.             HideCaret(hWnd);
  126.             KermPaint(ps.hdc, ps.rcPaint);
  127.             ShowCaret(hWnd);
  128.             EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  129.             break;
  130.      
  131.         default:
  132.             return(DefWindowProc(hWnd,message,wParam,lParam));
  133.             break;
  134.      
  135.         }
  136.     }
  137.      
  138. /* messages for the Kermit file transfer popup windows */
  139.      
  140.     else if (hWnd == hRXWnd) {
  141.      
  142.     switch(message) {
  143.      
  144.         case WM_PAINT:
  145.             BeginPaint(hWnd,(LPPAINTSTRUCT)&ps);
  146.         printf("%s %s %s\n", StateLabel, PacketLabel, FileLabel);
  147.         TextOut(ps.hdc,0,2,(LPSTR)StateLabel,strlen(StateLabel));
  148.         TextOut(ps.hdc,0,CharHeight+2,
  149.             (LPSTR)PacketLabel,strlen(PacketLabel));
  150.         TextOut(ps.hdc,0,2*CharHeight+2,
  151.             (LPSTR)FileLabel,strlen(FileLabel));
  152.         TextOut(ps.hdc,9*CharWidth,2,(LPSTR)StateStr,1);
  153.         TextOut(ps.hdc,10*CharWidth,CharHeight+2,
  154.             (LPSTR)PacketStr,strlen(PacketStr));
  155.             TextOut(ps.hdc,8*CharWidth,2*CharHeight+2,
  156.             (LPSTR)filnam1,strlen(filnam1));
  157.             EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  158.             break;
  159.      
  160.         case WM_SHOWWINDOW:
  161. /* if not intercepted, the file transfer window will hide with the main
  162.  *  window.  This should be made into an option.
  163.  */
  164.         break;
  165.      
  166.         default:
  167.             return(DefWindowProc(hWnd,message,wParam,lParam));
  168.             break;
  169.      
  170.         }
  171.     }
  172.     else
  173.         return(DefWindowProc(hWnd,message,wParam,lParam));
  174.     return(0L);
  175. }/* WinKermWndProc */
  176.      
  177. /***************************************************************************
  178. *
  179. * KermPaint
  180. *
  181. * Paint the main kermit window from the contents of the memor screen bnffer.
  182. *
  183. * Entry: Handle to the main kermit window display context
  184. *     and invalid rectangle.
  185. *
  186. * Exit: Kermit main window updated.
  187. *
  188. ***************************************************************************/
  189. void NEAR KermPaint(hDC, Rect)
  190. HDC hDC;
  191. RECT Rect;
  192. {
  193.      
  194.     int i, displ, len;
  195.     int FirstToCurrent;
  196.     int LinesToPrint;
  197.     int StartPoint;
  198.     int HighLinesToPrint;
  199.      
  200.     int LeftCol, RightCol;
  201.     int TopLine, BottomLine;
  202.     int LeftRect;
  203.     int temp;
  204.      
  205.     LeftCol = Rect.left / CharWidth;
  206.     RightCol = (Rect.right + CharWidth - 1) / CharWidth;
  207.     LeftRect = LeftCol * CharWidth;
  208.      
  209.     TopLine = Rect.top / CharHeight;
  210.     BottomLine = (Rect.bottom + CharHeight - 1) / CharHeight;
  211.      
  212.     FirstToCurrent = CurrentLine - FirstLine;
  213.     if (FirstToCurrent < 0)
  214.     FirstToCurrent += MaxChars;
  215.     LinesToPrint = min(MaxLinesOnScreen, 1 + FirstToCurrent/LineIncrement);
  216.     StartPoint = CurrentLine - (LinesToPrint - 1) * LineIncrement;
  217.      
  218.     if (StartPoint >= 0) {
  219.     for (i=0; i < LinesToPrint; i++) {
  220.         displ = StartPoint + LineIncrement * i;
  221.         len = strlen(ScreenBuf + displ);
  222.         if ((i < TopLine) || (i > BottomLine))
  223.         continue;
  224.         if (len <= LeftCol)
  225.         continue;
  226.         temp = min(len, RightCol) - LeftCol;    
  227.         TextOut(hDC,LeftRect,i*CharHeight,
  228.             (LPSTR)(ScreenBuf+ displ + LeftCol), temp);
  229.     }
  230.     }
  231.     else {
  232.     HighLinesToPrint = (-StartPoint / LineIncrement);
  233.     StartPoint += MaxChars;
  234.      
  235.     for (i = 0; i < HighLinesToPrint; i++) {
  236.         displ = StartPoint + LineIncrement * i;
  237.         len = strlen(ScreenBuf + displ);
  238.         if ((i < TopLine) || (i > BottomLine))
  239.         continue;
  240.         if (len <= LeftCol)
  241.         continue;
  242.         temp = min(len, RightCol) - LeftCol;    
  243.         TextOut(hDC,LeftRect,i*CharHeight,
  244.             (LPSTR)(ScreenBuf+ displ + LeftCol), temp);
  245.     }
  246.      
  247.     for (i = HighLinesToPrint; i < LinesToPrint; i++) {
  248.         displ = LineIncrement * (i - HighLinesToPrint);
  249.         len = strlen(ScreenBuf + displ);
  250.         if ((i < TopLine) || (i > BottomLine))
  251.         continue;
  252.         if (len <= LeftCol)
  253.         continue;
  254.         temp = min(len, RightCol) - LeftCol;    
  255.         TextOut(hDC,LeftRect,i*CharHeight,
  256.             (LPSTR)(ScreenBuf+ displ + LeftCol), temp);
  257.     }
  258.     }
  259.     Xpos = CharWidth * len;
  260.     Ypos = CharHeight * (i - 1);
  261.     SetCaretPos(Xpos, Ypos);
  262. }
  263.