home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Loisirs 18
/
cd.iso
/
PLANETE
/
FINGER31
/
FINGER.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-25
|
20KB
|
647 lines
//
// Finger Version 3.1, a Windows Sockets Finger Client
//
// Copyright 1992, 1993 Network Research Corporation
//
// Permission to use, modify, and distribute this software and its
// documentation for any purpose and without fee is hereby granted, provided
// that the above copyright notice appears in all copies and that both
// that copyright notice and this permission notice appear in supporting
// documentation. NRC makes no claims as to the suitability of this software
// for any purpose.
//
// Module FINGER provides the user interface for the finger client, and
// depends on NETWRK for TCP/IP network services, and upon DSPLIST
// retrieve and dispose of "display lists". The display list represents
// the remote finger server's return in a form suitable for scrolling text
// display. FINGER prompts the user for a host name (or internet address),
// invokes NETWRK to finger the specified host, and paints the window
// client area with the returned display list. FINGER uses a view
// (a logical window onto a portion of the display list) to render
// that portion of the list which is currently visable.
//
// 02/12/92 Lee Murach Created.
// 06/19/92 Mark Towfiq Adapted to Windows Socket draft rev 1.0.
// 09/25/92 Ian Merritt Adapted for Windows Sockets 1.0B compatability.
// 10/20/92 Lee Murach Restructured (Ray Duncan-ized) & added scrollbars.
// 12/02/92 Lee Murach Split FingerHost() into FingerStart() &
// FingerFinish(), for NETWORK_ module interface.
// 03/25/93 Lee Murach Added per-user finger support.
//
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#include "finger.h"
#define MAXTEXT 132
#define THUMBPOS LOWORD(lParam) // Win 16
typedef struct // associates an error code with text
{
UINT err;
char *sztext;
} ERRENTRY;
int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LONG FAR APIENTRY FrameWndProc(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
BOOL APIENTRY HostDlgProc(HWND hDlg, UINT wMsg, UINT wParam, LONG lParam);
BOOL FAR APIENTRY AboutDlgProc(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
BOOL InitInstance(HANDLE hInstance, int nCmdShow);
BOOL InitApp(HANDLE hInstance);
LONG DoPaint(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoSize(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoCommand(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoDestroy(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoMouseMove(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoMenuHost(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoVScroll(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoActivate(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoClose(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoMenuExit(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
LONG DoMenuAbout(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam);
VOID Repaint(VOID);
VOID PosView(int nlines);
VOID ReportWSError(UINT Err);
VOID RelScroll(HWND hWnd, int nlines);
VOID SetWinCaption(VOID);
VOID SetScroll(VOID);
VOID ReportWSError(UINT Err);
char szHostName[MAXHOST+1] = "";// name of host to finger
char szUser[MAXUSER+1] = ""; // query for this user id (can be null)
char szAppName[] = "Finger"; // application's name
LINEITEM *pLineItems = 0; // ptr to display list LINEITEMS
int nLineItems = 0; // number of items in display list
LINEITEM *pTopLine; // pts to topmost displayable LINEITEM
int nTopLine = 0; // line number of topmost displayed line
int nClientLines; // # of text lines in view
int CharY; // pixel character height
HWND hFrame; // finger main window handle
HMENU hMenu; // main window menu handle
HANDLE hInst; // this instance of finger
HCURSOR hCursor; // current cursor (either wait or normal)
WSADATA WSAData; // windows sockets info return
DECODEWORD frameMsgs[] = // windows messages & handlers
{
WM_ACTIVATE, DoActivate,
WM_CLOSE, DoClose,
WM_COMMAND, DoCommand,
WM_DESTROY, DoDestroy,
WM_MOUSEMOVE, DoMouseMove,
WM_PAINT, DoPaint,
WM_SIZE, DoSize,
WM_VSCROLL, DoVScroll,
WM_KEYDOWN, DoVScroll,
};
DECODEWORD menuItems[] = // menu items & associated handlers
{
IDM_HOST, DoMenuHost,
IDM_EXIT, DoMenuExit,
IDM_ABOUT, DoMenuAbout,
};
ERRENTRY wsErrs[] = // error text for windows sockets errors
{
WSAVERNOTSUPPORTED, "This version of Windows Sockets is not supported",
WSASYSNOTREADY, "Windows Sockets is not present or is not responding",
};
ERRENTRY finErrs[] = // finger specific error text
{
FE_NOPORT, "Cannot locate port for finger service",
FE_NOHOST, "Unrecognized host name",
FE_NOSOCK, "Cannot obtain socket for connection",
FE_NOCONN, "Cannot connect to remote server",
FE_NOSEND, "Cannot send query to remote server",
FE_NORECV, "Error occurred during retrieval"
};
//
// WinMain -- windows calls this to start the application.
//
int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg; // holds current message
int err;
hInst = hInstance; // save our instance handle
if (!hPrevInstance) // if first instance,
if (!InitApp(hInstance)) // register window classes
{
MessageBox(hFrame, "Can't initialize Finger", szAppName,
MB_ICONSTOP | MB_OK);
return(FALSE);
}
if (!InitInstance(hInstance, nCmdShow)) // per instance initialization &
{ // window creation
MessageBox(hFrame, "Can't initialize Finger", szAppName,
MB_ICONSTOP | MB_OK);
return(FALSE);
}
if (err = WSAStartup(WSVERSION, &WSAData))// register task with
{ // winsock tcp/ip API
ReportWSError(err);
DestroyWindow(hFrame); // kill application window &
} // signal app exit
while (GetMessage(&msg, NULL, 0, 0)) // loop til WM_QUIT
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
WSACleanup(); // disconnect from winsock
return msg.wParam; // return to windows
}
//
// InitApp -- initialization for all instances of application.
// Registers main window class.
//
BOOL InitApp(HANDLE hInstance)
{
WNDCLASS wndclass;
InitNetApp(); // initializes (per application) network module
wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wndclass.lpfnWndProc = FrameWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInst, "FingerIcon");
wndclass.hCursor = NULL;
wndclass.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
wndclass.lpszMenuName = "FingerMenu";
wndclass.lpszClassName = szAppName;
return(RegisterClass(&wndclass));
}
//
// InitInstance -- initializes this instance of app, and creates windows.
//
BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
HDC hdc; // handle of device context
TEXTMETRIC tm; // contains font dimensions
RECT rect; // outer dimensions of window
hFrame = CreateWindow( szAppName, szAppName,
WS_OVERLAPPEDWINDOW | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL