home *** CD-ROM | disk | FTP | other *** search
/ CD Loisirs 18 / cd.iso / PLANETE / FINGER31 / FINGER.C < prev    next >
C/C++ Source or Header  |  1993-03-25  |  20KB  |  647 lines

  1. //
  2. // Finger Version 3.1, a Windows Sockets Finger Client
  3. //
  4. // Copyright 1992, 1993 Network Research Corporation
  5. //
  6. // Permission to use, modify, and distribute this software and its
  7. // documentation for any purpose and without fee is hereby granted, provided
  8. // that the above copyright notice appears in all copies and that both
  9. // that copyright notice and this permission notice appear in supporting
  10. // documentation.  NRC makes no claims as to the suitability of this software
  11. // for any purpose.
  12. //
  13. // Module FINGER provides the user interface for the finger client, and
  14. // depends on NETWRK for TCP/IP network services, and upon DSPLIST
  15. // retrieve and dispose of "display lists".  The display list represents
  16. // the remote finger server's return in a form suitable for scrolling text
  17. // display.  FINGER prompts the user for a host name (or internet address),
  18. // invokes NETWRK to finger the specified host, and paints the window
  19. // client area with the returned display list.  FINGER uses a view
  20. // (a logical window onto a portion of the display list) to render
  21. // that portion of the list which is currently visable.
  22. //
  23. // 02/12/92 Lee Murach     Created.
  24. // 06/19/92 Mark Towfiq    Adapted to Windows Socket draft rev 1.0.
  25. // 09/25/92 Ian Merritt    Adapted for Windows Sockets 1.0B compatability.
  26. // 10/20/92 Lee Murach     Restructured (Ray Duncan-ized) & added scrollbars.
  27. // 12/02/92 Lee Murach     Split FingerHost() into FingerStart() &
  28. //                         FingerFinish(), for NETWORK_ module interface.
  29. // 03/25/93 Lee Murach     Added per-user finger support.
  30. //
  31.  
  32. #include <windows.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <winsock.h>
  36. #include "finger.h"
  37.  
  38. #define MAXTEXT   132
  39. #define THUMBPOS  LOWORD(lParam)    // Win 16
  40.  
  41. typedef struct                      // associates an error code with text
  42. {
  43.    UINT err;
  44.    char *sztext;
  45. } ERRENTRY;
  46.  
  47. int  APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
  48. LONG FAR APIENTRY FrameWndProc(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  49. BOOL APIENTRY HostDlgProc(HWND hDlg, UINT wMsg, UINT wParam, LONG lParam);
  50. BOOL FAR APIENTRY AboutDlgProc(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  51. BOOL InitInstance(HANDLE hInstance, int nCmdShow);
  52. BOOL InitApp(HANDLE hInstance);
  53. LONG DoPaint(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  54. LONG DoSize(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  55. LONG DoCommand(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  56. LONG DoDestroy(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  57. LONG DoMouseMove(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  58. LONG DoMenuHost(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  59. LONG DoVScroll(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  60. LONG DoActivate(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  61. LONG DoClose(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  62. LONG DoMenuExit(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  63. LONG DoMenuAbout(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
  64. VOID Repaint(VOID);
  65. VOID PosView(int nlines);
  66. VOID ReportWSError(UINT Err);
  67. VOID RelScroll(HWND hWnd, int nlines);
  68. VOID SetWinCaption(VOID);
  69. VOID SetScroll(VOID);
  70. VOID ReportWSError(UINT Err);
  71.  
  72. char     szHostName[MAXHOST+1] = "";// name of host to finger
  73. char     szUser[MAXUSER+1] = "";    // query for this user id (can be null)
  74. char     szAppName[] = "Finger";    // application's name
  75. LINEITEM *pLineItems = 0;           // ptr to display list LINEITEMS
  76. int      nLineItems = 0;            // number of items in display list
  77. LINEITEM *pTopLine;                 // pts to topmost displayable LINEITEM
  78. int      nTopLine = 0;              // line number of topmost displayed line
  79. int      nClientLines;              // # of text lines in view
  80. int      CharY;                     // pixel character height
  81. HWND     hFrame;                    // finger main window handle
  82. HMENU    hMenu;                     // main window menu handle
  83. HANDLE   hInst;                     // this instance of finger
  84. HCURSOR  hCursor;                   // current cursor (either wait or normal)
  85. WSADATA  WSAData;                     // windows sockets info return
  86.  
  87. DECODEWORD frameMsgs[] =            // windows messages & handlers
  88. {
  89.    WM_ACTIVATE,   DoActivate,
  90.    WM_CLOSE,      DoClose,
  91.    WM_COMMAND,    DoCommand,
  92.    WM_DESTROY,    DoDestroy,
  93.    WM_MOUSEMOVE,  DoMouseMove,
  94.    WM_PAINT,      DoPaint,
  95.    WM_SIZE,       DoSize,
  96.    WM_VSCROLL,    DoVScroll,
  97.    WM_KEYDOWN,    DoVScroll,
  98. };
  99.  
  100. DECODEWORD menuItems[] =            // menu items & associated handlers
  101. {
  102.    IDM_HOST,      DoMenuHost,
  103.    IDM_EXIT,      DoMenuExit,
  104.    IDM_ABOUT,     DoMenuAbout,
  105. };
  106.  
  107. ERRENTRY wsErrs[] =                 // error text for windows sockets errors
  108. {
  109.    WSAVERNOTSUPPORTED,  "This version of Windows Sockets is not supported",
  110.    WSASYSNOTREADY,      "Windows Sockets is not present or is not responding",
  111. };
  112.  
  113. ERRENTRY finErrs[] =                // finger specific error text
  114. {
  115.    FE_NOPORT,  "Cannot locate port for finger service",
  116.    FE_NOHOST,  "Unrecognized host name",
  117.    FE_NOSOCK,  "Cannot obtain socket for connection",
  118.    FE_NOCONN,  "Cannot connect to remote server",
  119.    FE_NOSEND,  "Cannot send query to remote server",
  120.    FE_NORECV,  "Error occurred during retrieval"
  121. };
  122.  
  123. //
  124. // WinMain -- windows calls this to start the application.
  125. //
  126. int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  127.     LPSTR lpCmdLine, int nCmdShow)
  128. {
  129.    MSG msg;                                  // holds current message
  130.    int err;
  131.  
  132.    hInst = hInstance;                        // save our instance handle
  133.  
  134.    if (!hPrevInstance)                       // if first instance,
  135.       if (!InitApp(hInstance))               // register window classes
  136.       {
  137.          MessageBox(hFrame, "Can't initialize Finger", szAppName,
  138.             MB_ICONSTOP | MB_OK);
  139.          return(FALSE);
  140.       }
  141.  
  142.    if (!InitInstance(hInstance, nCmdShow))   // per instance initialization &
  143.    {                                         // window creation
  144.       MessageBox(hFrame, "Can't initialize Finger", szAppName,
  145.          MB_ICONSTOP | MB_OK);
  146.          return(FALSE);
  147.    }
  148.  
  149.    if (err = WSAStartup(WSVERSION, &WSAData))// register task with
  150.    {                                         // winsock tcp/ip API
  151.       ReportWSError(err);            
  152.       DestroyWindow(hFrame);                 // kill application window &
  153.    }                                         // signal app exit
  154.  
  155.    while (GetMessage(&msg, NULL, 0, 0))      // loop til WM_QUIT
  156.    {
  157.       TranslateMessage(&msg);
  158.       DispatchMessage(&msg);
  159.    }
  160.  
  161.    WSACleanup();                             // disconnect from winsock
  162.    return msg.wParam;                        // return to windows
  163. }
  164.  
  165. //
  166. // InitApp -- initialization for all instances of application.
  167. // Registers main window class.
  168. //
  169. BOOL InitApp(HANDLE hInstance)
  170. {
  171.    WNDCLASS    wndclass;
  172.  
  173.    InitNetApp();  // initializes (per application) network module
  174.  
  175.    wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  176.    wndclass.lpfnWndProc   = FrameWndProc;
  177.    wndclass.cbClsExtra    = 0;
  178.    wndclass.cbWndExtra    = 0;
  179.    wndclass.hInstance     = hInstance;
  180.    wndclass.hIcon         = LoadIcon(hInst, "FingerIcon");
  181.    wndclass.hCursor       = NULL;
  182.    wndclass.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  183.    wndclass.lpszMenuName  = "FingerMenu";
  184.    wndclass.lpszClassName = szAppName;
  185.  
  186.    return(RegisterClass(&wndclass));
  187. }
  188.  
  189. //
  190. // InitInstance -- initializes this instance of app, and creates windows.
  191. //
  192. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  193. {
  194.    HDC hdc;                            // handle of device context
  195.    TEXTMETRIC tm;                      // contains font dimensions
  196.    RECT rect;                          // outer dimensions of window
  197.  
  198.    hFrame = CreateWindow( szAppName, szAppName,
  199.                WS_OVERLAPPEDWINDOW | WS_VSCROLL,
  200.                CW_USEDEFAULT, CW_USEDEFAULT,
  201.                CW_USEDEFAULT, CW_USEDEFAULT,
  202.                NULL, NULL, hInstance, NULL