home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / winsock / wsftp32 / ws_paint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  5.5 KB  |  179 lines

  1. /***************************************************************************
  2.   Windows Sockets Client Application Support Module
  3.  
  4.   Written by:
  5.       John A. Junod             Internet: <junodj@gordon-emh2.army.mil>
  6.       267 Hillwood Street                 <zj8549@trotter.usma.edu>
  7.       Martinez, GA 30907      Compuserve: 72321,366 
  8.  
  9.   This program executable and all source code is released into the public
  10.   domain.  It would be nice (but is not required) to give me a little 
  11.   credit for any use of this code.
  12.  
  13.   THE INFORMATION AND CODE PROVIDED IS PROVIDED AS IS WITHOUT WARRANTY 
  14.   OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  15.   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  16.   PURPOSE. IN NO EVENT SHALL JOHN A. JUNOD BE LIABLE FOR ANY DAMAGES 
  17.   WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS 
  18.   OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF JOHN A. JUNOD HAS BEEN 
  19.   ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  20.  
  21. *****************************************************************************/
  22. /*
  23.   MODULE: WS_PAINT.C  (main window (debug) display routines)
  24. */
  25.  
  26. #include "ws_glob.h"
  27. #include "ws_ftp.h"
  28. #include "version.h"
  29.  
  30. #include <stdarg.h>
  31.  
  32. extern struct win_info DBUGWINDOW;
  33.  
  34. void ReleaseDisplayMem()       { ReleaseWindowMem(&DBUGWINDOW); }
  35.  
  36. void DoAddLine(LPSTR szString) { DoAddWindowLine(&DBUGWINDOW,szString); }
  37.  
  38. void DoPrintf(char *szFormat,...)
  39. {
  40.    va_list vaArgs;
  41.    static char szBuf[256];
  42.  
  43.    va_start(vaArgs,szFormat);
  44.    if(vsprintf(szBuf,szFormat,vaArgs)!=EOF)
  45.      DoAddWindowLine(&DBUGWINDOW,szBuf);
  46.    va_end(vaArgs);
  47. }
  48.  
  49. int GetLocalInfo()
  50. {
  51.   int nRc;
  52.   struct hostent *hostptr;
  53.  // char *ptr;
  54.   struct in_addr *iptr;
  55.  
  56. //DoWindowPrintf(&DBUGWINDOW,"System Status: %s", (LPSTR)WSAData.szSystemStatus);
  57.   if((nRc=gethostname((LPSTR)szString,
  58.              MAXHOSTNAMELEN))==SOCKET_ERROR)
  59.     ReturnWSError(WSAGetLastError(),&szMsgBuf2[strlen(szMsgBuf2)]);
  60.   else
  61.     DoWindowPrintf(&DBUGWINDOW,"Local Hostname: %s",szString);
  62.  
  63.   if(!nRc)
  64.   {
  65.     if((hostptr=gethostbyname(szString))==NULL) {
  66.       ReportWindowWSError(&DBUGWINDOW,"gethostbyname",WSAGetLastError());
  67.     } else {
  68.       while ( (iptr = (struct in_addr *) *(hostptr->h_addr_list)) != NULL) {
  69.         DoWindowPrintf(&DBUGWINDOW,"Local Address: %s",inet_ntoa(*iptr));
  70.         hostptr->h_addr_list++;
  71.       }
  72.     }
  73.   }
  74.   DoWindowPrintf(&DBUGWINDOW,"WINSOCK.DLL: %s",(LPSTR)WSAData.szDescription);
  75.   DoWindowPrintf(&DBUGWINDOW,"WS_FTP version %s written by John A. Junod/L. Kahn",VERSION);
  76.   return(TRUE);
  77. }
  78.  
  79. void ReleaseWindowMem(struct win_info *Window)
  80. {
  81.   int nIndex;
  82.   for(nIndex=0;nIndex<Window->nMemPtr;nIndex++)
  83.     GlobalFree(Window->hGMem[nIndex]);
  84.   Window->nMemPtr=0;
  85. }
  86.  
  87. void DoAddWindowLine(struct win_info *Window,LPSTR szString)
  88. {
  89.   GLOBALHANDLE hGlobalMemory;
  90.   LPSTR lpGlobalMemory;
  91.   int nIndex;
  92.   RECT rect;
  93.  
  94.   if(!(bVerbose) && szString[0]=='[')
  95.     return;
  96.  
  97.  // lgk only don't print if we are not in debug mode zzz
  98.  
  99.   if ((szString[0]!='[') || DEBUGGING_ON)
  100.     SetStatus((LPSTR)szString);
  101. // SendMessage(hTxtStatus,WM_SETTEXT,0,(LONG)szString);
  102.   // added in some error checking to try to eliminate GPFs
  103.   if(szString) {
  104.     nIndex=strlen(szString);
  105.     if(nIndex>0 && (hGlobalMemory=GlobalAlloc(GMEM_MOVEABLE,nIndex))!=NULL) {
  106.       if((lpGlobalMemory=GlobalLock(hGlobalMemory))!=NULL) {
  107.         lstrcpy(lpGlobalMemory,szString);
  108.         GlobalUnlock(hGlobalMemory);
  109.         if(Window->nMemPtr<90) {
  110.           Window->hGMem[Window->nMemPtr++]=hGlobalMemory;
  111.         } else {
  112.           if(GlobalFree(Window->hGMem[0])==NULL) {
  113.             for(nIndex=0;nIndex<90;nIndex++)
  114.               Window->hGMem[nIndex]=Window->hGMem[nIndex+1];
  115.             Window->hGMem[Window->nMemPtr-1]=hGlobalMemory;
  116.           }
  117.         }
  118.       }
  119.     }
  120.   }
  121.   GetClientRect(Window->hWnd,&rect);
  122.   rect.top=min(0,(Window->nMemPtr-Window->nVpos-1))*Window->nLineHeight;
  123.  
  124.   if(Window->nMemPtr > (Window->nVpos+Window->nScreenRows))
  125.     PostMessage(Window->hWnd,WM_VSCROLL,SB_LINEDOWN,0L);
  126.   else
  127.     InvalidateRect(Window->hWnd,&rect,TRUE);
  128.  
  129.   UpdateWindow(Window->hWnd);
  130. }
  131.  
  132. void DoWindowPrintf(struct win_info *Window,char *szFormat,...)
  133. {
  134.    va_list vaArgs;
  135.    static char szBuf[256];
  136.  
  137.    va_start(vaArgs,szFormat);
  138.    if(vsprintf(szBuf,szFormat,vaArgs)!=EOF)
  139.      DoAddWindowLine(Window,szBuf);
  140.    va_end(vaArgs);
  141. }
  142.  
  143. void DoWindowPaint(struct win_info *Window)
  144. {
  145.   HDC         hDC;   // handle for the display device
  146.   PAINTSTRUCT ps;    // holds PAINT information
  147. //  int         nRc;
  148.   int         nIndex;
  149.   LPSTR       lpMem;
  150.  
  151.   RECT rRect;
  152.   TEXTMETRIC tm;
  153.  
  154.   memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  155.   hDC = BeginPaint(Window->hWnd, &ps);
  156.   // Included as the background is not a pure color
  157.   SetBkMode(hDC, TRANSPARENT);
  158.   GetTextMetrics(hDC,&tm);
  159.   Window->nLineHeight=tm.tmHeight+tm.tmExternalLeading;
  160.   GetClientRect(Window->hWnd,&rRect);
  161.   Window->nScreenRows=rRect.bottom/Window->nLineHeight;
  162.  
  163.   if(Window->nScreenRows >= Window->nMemPtr)
  164.       ShowScrollBar(Window->hWnd,SB_VERT,FALSE);
  165.   else
  166.       ShowScrollBar(Window->hWnd,SB_VERT,TRUE);
  167.  
  168.   for(nIndex=0;(nIndex+Window->nVpos)<Window->nMemPtr;nIndex++) {
  169.     lpMem=GlobalLock(Window->hGMem[nIndex+Window->nVpos]);
  170.     if(lpMem!=NULL) {
  171.       TextOut(hDC,20,nIndex*Window->nLineHeight,lpMem,lstrlen(lpMem));
  172.       GlobalUnlock(Window->hGMem[nIndex+Window->nVpos]);
  173.     }
  174.   }
  175.   // Inform Windows painting is complete
  176.   EndPaint(Window->hWnd, &ps);
  177. }
  178.  
  179.