⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 finger.c

📁 finger client程序
💻 C
📖 第 1 页 / 共 2 页
字号:
LONG DoMenuExit(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   SendMessage(hWnd, WM_CLOSE, 0, 0);
   return(FALSE);
}

//
// DoMenuAbout -- respond to "About..." menu selection by invoking the
// "About" dialog box.
//
LONG DoMenuAbout(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   WNDPROC lpProcAbout;

   lpProcAbout = MakeProcInstance((WNDPROC)AboutDlgProc, hInst);
   DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
   FreeProcInstance(lpProcAbout);

   return(FALSE);
}

//
// DoDestroy -- posts a WM_QUIT message to the task's win queue, which
// causes the main translate & dispatch loop to exit, and the app to
// terminate.
//
LONG DoDestroy(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   PostQuitMessage(0);
   return(FALSE);
}

//
// DoClose -- cleans up display list & tells windows to deallocate
// our window.
//
LONG DoClose(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   FreeLineList(pLineItems);
   DestroyWindow(hWnd);

   return(FALSE);
}

//
// DoActivate -- grabs the keyboard focus whenever our deminimized window
// is activated.  This is so we can respond to VK_HOME, VK_END, etc.
// virtual keys for scrolling. HIWORD(lParam) is TRUE for minimized, while
// LOWORD(wParam) is FALSE for activation message.
// 
LONG DoActivate(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   if (!HIWORD(lParam) && LOWORD(wParam))
      SetFocus(hFrame);

   return FALSE;
}

//
// DoMouseMove -- resets the cursor back to the current cursor (either
// a wait, or normal cursor) because Windows will otherwise redraw it
// using the window's class.
//
LONG DoMouseMove(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   SetCursor(hCursor);
   return(FALSE);
}

//
// PosView -- repositions the view relative to the top of the display list.
// The view is a logical "window" onto the display list.  The frame window's
// client area is painted with the view's contents.
//
VOID PosView(int nlines)
{
   LINEITEM *pline;
   int i;

   pline = pLineItems;              // root of LINEITEM list

   for (i = 0; i < nlines; i++)
   {
      if (!pline)
         break;
      else
         pline = pline->next;
   }

   pTopLine = pline;                // ptr to LINEITEM in topmost view line
   nTopLine =+ nlines;              // offset of topmost view line
}

//
// DoPaint -- Paint the client area with the contents of the view.
//
LONG DoPaint(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   HDC hdc;                   // scratch device context
   PAINTSTRUCT ps;            // scratch paint structure
   LINEITEM *pline;           // pts to topmost displayable LINEITEM
   int i;

   pline = pTopLine;
   hdc = BeginPaint(hWnd, &ps);

   for (i = 0; i <= nClientLines; i++)
   {
      if (pline)
      {
         TextOut(hdc, 0, i * CharY, pline->sztext, pline->len);
         pline = pline->next;
      }
      else
         break;
   }

   EndPaint(hWnd, &ps);
   return(FALSE);
}

//
// Repaint -- force refresh of client window.
// 
VOID Repaint(VOID)
{
   InvalidateRect(hFrame, NULL, TRUE);
}

//
// SetScroll -- sets the vertical scroll range to the length of the display
// list.  The Scrollbar disappears when the list fits within the view.
//
VOID SetScroll(VOID)
{
   if (nLineItems > nClientLines)
      SetScrollRange(hFrame, SB_VERT, 0, nLineItems - nClientLines, FALSE);
   else
      SetScrollRange(hFrame, SB_VERT, 0, 0, FALSE);
 
   SetScrollPos(hFrame, SB_VERT, nTopLine, TRUE);
}

// number of lines below the bottom of the view.
#define NLINESBELOW (nLineItems - nTopLine - nClientLines)

//
// DoVScroll -- process WM_VSCROLL & WM_KEYDOWN for main window.
//
LONG DoVScroll(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   switch (LOWORD(wParam))
   {
      case VK_HOME:
      case SB_TOP:
         if (nTopLine > 0)
            RelScroll(hWnd, -nTopLine);
         break;

      case VK_END:
      case SB_BOTTOM:
         if (NLINESBELOW)
            RelScroll(hWnd, NLINESBELOW);
         break;

      case VK_PRIOR:
      case SB_PAGEUP:
         if (nTopLine > 0)
            RelScroll(hWnd, max(-nClientLines, -nTopLine));
         break;

      case VK_NEXT:
      case SB_PAGEDOWN:
         if (NLINESBELOW)
            RelScroll(hWnd, min(nClientLines, NLINESBELOW));
         break;

      case VK_UP:
      case SB_LINEUP:
         if (nTopLine > 0)
            RelScroll(hWnd, -1);
         break;

      case VK_DOWN:
      case SB_LINEDOWN:
         if (NLINESBELOW)
            RelScroll(hWnd, 1);
         break;

      case SB_THUMBTRACK:
         RelScroll(hWnd, THUMBPOS - nTopLine);
         break;
   }

   SetScrollPos(hFrame, SB_VERT, nTopLine, TRUE);
   return(FALSE);
}

//
// RelScroll -- scroll up/down nlines from present position
//
VOID RelScroll(HWND hWnd, int nlines)
{
   PosView(nTopLine + nlines);
   ScrollWindow(hWnd, 0, -nlines * CharY, NULL, NULL);
   UpdateWindow(hWnd);
}

//
// DoSize -- respond to WM_SIZE by recalculating the number of text lines
// in the main window's client area.
//
LONG DoSize(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   nClientLines = HIWORD(lParam) / CharY;
   PosView(0);
   SetScroll();

   return(FALSE);
}

//
// SetWinCaption -- set the frame window caption according to last
// host fingered.
//
VOID SetWinCaption(VOID)
{
   char szcaption[80];
   
   strcpy(szcaption, szAppName);
   strcat(szcaption, " - ");
   strcat(szcaption, szHostName);

   SetWindowText(hFrame, szcaption);
}

//
// ReportWSError -- prompt user with a windows sockets error message.
//
VOID ReportWSError(UINT Err)
{
   int i;
   char szerr[40];

   for (i = 0; i < dim(wsErrs); i++)
   {
      if (Err == wsErrs[i].err)
      {
         MessageBox(hFrame, wsErrs[i].sztext, szAppName,
            MB_ICONSTOP | MB_OK);
         return;
      }
   }

   wsprintf(szerr, "Windows Sockets reports error %04x", Err);
   MessageBox(hFrame, szerr, szAppName, MB_ICONSTOP | MB_OK);
}

//
// ReportFingerErr -- prompt user with a finger specific error
//
VOID ReportFingerErr(UINT Err)
{
   int i;

   for (i = 0; i < dim(finErrs); i++)
   {
      if (Err == finErrs[i].err)
      {
         MessageBox(hFrame, finErrs[i].sztext, szAppName,
            MB_ICONSTOP | MB_OK);
         return;
      }
   }

   MessageBox(hFrame, "Unrecognized finger error", szAppName,
      MB_ICONSTOP | MB_OK);
}

//
// HostDlgProc -- dialog box proc for "host dialog".
// This box queries user for a host name in response to the user's
// selection of the "Host..." main menu item.
//
BOOL APIENTRY HostDlgProc(HWND hDlg, UINT wMsg, UINT wParam, LONG lParam)
{
   switch(wMsg)
   {
      case WM_INITDIALOG:
         SetDlgItemText(hDlg, IDC_HOSTNAME, szHostName);
         SetDlgItemText(hDlg, IDC_USER, szUser);
         return TRUE;
 
      case WM_COMMAND:
         switch(wParam)
         {
            case IDOK:
               GetDlgItemText(hDlg, IDC_HOSTNAME, szHostName, MAXHOST);
               GetDlgItemText(hDlg, IDC_USER, szUser, MAXUSER);
               EndDialog(hDlg, IDOK);
               return TRUE;

            case IDCANCEL:
               EndDialog(hDlg, IDCANCEL);
               return TRUE;
         }
         break;
   }

   return FALSE;
}

//
// AboutDlgProc -- callback for the "About" dialog box
//
BOOL FAR APIENTRY AboutDlgProc(HWND hWnd, UINT wMsg, UINT wParam, LONG lParam)
{
   if ((wMsg == WM_COMMAND) && (wParam == IDOK))   // dismiss dialog if OK
      EndDialog(hWnd, 0);
 
   return(FALSE);                                  // otherwise just sit there
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -