home *** CD-ROM | disk | FTP | other *** search
/ The Best Internet Programs / BESTINTERNET.bin / internet / winftp / ws_paint.c < prev   
C/C++ Source or Header  |  1993-12-08  |  5KB  |  169 lines

  1. /*
  2.   MODULE: WS_PAINT.C  (main window (debug) display routines)
  3. */
  4.  
  5. #include "ws_glob.h"
  6. #include "winftp.h"
  7.  
  8. #include <stdarg.h>
  9.  
  10. int nLineHeight=5;
  11. int nScreenRows=10;
  12.  
  13. #define  MAX_SIZE   100
  14. #define  MAX_MSG    100
  15.  
  16. LPSTR lpDebugMsg=NULL;
  17. LPSTR lpMem[MAX_MSG+1];
  18.  
  19. #define LPDBG(x) (lpDebugMsg+(x*MAX_SIZE))
  20.  
  21. extern HWND hWndDbg;
  22.  
  23. //*************************************************************************
  24. //*************************************************************************
  25. int GetLocalInfo()
  26. {
  27.   int nRc;
  28.   struct hostent FAR *hostptr;
  29.   struct in_addr FAR *iptr;
  30.  
  31.   DoPrintf("Using %s",(LPSTR)WSAData.szDescription);
  32.   if (lstrlen (WSAData.szSystemStatus)>0)
  33.       DoPrintf("System Status: %s", (LPSTR)WSAData.szSystemStatus);
  34.   if ((nRc=gethostname ((LPSTR) szString, MAXHOSTNAMELEN))==SOCKET_ERROR)
  35.     ReportWSError("GetHostName",WSAGetLastError());
  36.   else
  37.     DoPrintf("Local Host: %s",szString);
  38.  
  39.   if(!nRc)
  40.   {
  41.     if((hostptr=gethostbyname(szString))==NULL) 
  42.     {
  43.       ReportWSError("gethostbyname",WSAGetLastError());
  44.     } 
  45.     else 
  46.     {
  47.       while ( (iptr = (struct in_addr *) *(hostptr->h_addr_list)) != NULL) 
  48.       {
  49.         DoPrintf("Local Address: %s", inet_ntoa (*iptr));
  50.         hostptr->h_addr_list++;
  51.       }
  52.     }
  53.   }
  54.   DoAddLine("WinFTP written by Santanu Lahiri");
  55.   return(TRUE);
  56. }
  57.  
  58. //*************************************************************************
  59. //*************************************************************************
  60. void ReleaseDisplayMem()
  61. {
  62. //  int nIndex;
  63. //  for (nIndex=0; nIndex<ptrhGMem; nIndex++)  GlobalFree (hGMem[nIndex]);
  64.   
  65.   if (lpDebugMsg!=NULL) GlobalFreePtr (lpDebugMsg);
  66.   ptrhGMem=0;
  67. }
  68.  
  69. //*************************************************************************
  70. //*************************************************************************
  71. void AddLineToLog (LPSTR lpStr)
  72. {
  73.   FILE *fp;
  74.   
  75.   if ((fp=fopen (szLogFile, "at"))!=NULL)
  76.   {
  77.     fprintf (fp, "%s\n", lpStr);
  78.     fclose (fp);
  79.   }
  80. }
  81.  
  82. //*************************************************************************
  83. //*************************************************************************
  84. void DoAddLine (LPSTR szString)
  85. {
  86.   int nLen;
  87.   RECT rect;
  88.  
  89.   if (lstrlen (szString)==0) return;
  90.   if (!(bVerbose) && szString[0]=='[') return;
  91.  
  92.   if (nLogFlag==MF_CHECKED) AddLineToLog (szString);
  93.   if (szString[0]!='[') SetStatus (hWndMain, (LPSTR) szString);
  94.   // added in some error checking to try to eliminate GPFs
  95.   if (szString) 
  96.   {
  97.     if (lpDebugMsg==NULL)
  98.     {
  99.       int nI;
  100.       
  101.       lpDebugMsg = GlobalAllocPtr (GHND, (MAX_MSG+1)*MAX_SIZE);
  102.       for (nI=0; nI<MAX_MSG; nI++) lpMem[nI] = LPDBG(nI);
  103.     }
  104.     nLen = lstrlen(szString);
  105.     if (nLen>0) 
  106.     {
  107.       if (ptrhGMem<(MAX_MSG-1)) ptrhGMem++;
  108.       else 
  109.       {
  110.         LPSTR lp = lpMem[0];
  111.         memmove (lpMem, lpMem+1, MAX_MSG*sizeof (LPSTR));
  112.         lpMem[MAX_MSG-1] = lp;
  113.       }
  114.       strncpy (lpMem[ptrhGMem], szString, MAX_SIZE-1);
  115.     }
  116.   }
  117.   GetClientRect(hWndDbg,&rect);
  118.   rect.top=min(0,(ptrhGMem-sVPos-1))*nLineHeight;
  119.  
  120.   if((UINT) ptrhGMem > (UINT) (sVPos+nScreenRows))
  121.     PostMessage(hWndDbg,WM_VSCROLL,SB_LINEDOWN,0L);
  122.   else
  123.     InvalidateRect(hWndDbg,&rect,TRUE);
  124.  
  125.   UpdateWindow(hWndDbg);
  126. }
  127.  
  128. //*************************************************************************
  129. //*************************************************************************
  130. void DoPrintf(char *szFormat,...)
  131. {
  132.    va_list vaArgs;
  133.    static char szBuf[256];
  134.  
  135.    va_start(vaArgs,szFormat);
  136.    if (vsprintf (szBuf,szFormat,vaArgs)!=EOF) DoAddLine (szBuf);
  137.    va_end(vaArgs);
  138. }
  139.  
  140. //*************************************************************************
  141. //*************************************************************************
  142. void DoPaint(HWND hWnd)
  143. {
  144.   HDC         hDC;   // handle for the display device
  145.   PAINTSTRUCT ps;    // holds PAINT information
  146.   UINT        nI;
  147.  
  148.   RECT rRect;
  149.   TEXTMETRIC tm;
  150.  
  151.   memset(&ps, 0x00, sizeof(PAINTSTRUCT));
  152.   hDC = BeginPaint(hWnd, &ps);
  153.   // Included as the background is not a pure color
  154.   SetBkMode(hDC, TRANSPARENT);
  155.   GetTextMetrics(hDC,&tm);
  156.   nLineHeight=tm.tmHeight+tm.tmExternalLeading;
  157.   GetClientRect(hWnd,&rRect);
  158.   nScreenRows = rRect.bottom/nLineHeight;
  159.   ShowScrollBar (hWnd, SB_VERT, (nScreenRows<ptrhGMem));
  160.   for (nI=0; (nI+sVPos) < (UINT) ptrhGMem; nI++) 
  161.   {
  162.     TextOut (hDC, 20, nI*nLineHeight, lpMem[nI+sVPos], lstrlen (lpMem[nI+sVPos]));
  163.   }
  164.   // Inform Windows painting is complete
  165.   EndPaint(hWnd, &ps);
  166. }
  167.  
  168.  
  169.