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

📄 23. 领略internet.txt

📁 本书介绍了在Microsoft Windows 98、Microsoft Windows NT 4.0和Windows NT 5.0下程序写作的方法
💻 TXT
📖 第 1 页 / 共 5 页
字号:
        
                          SetCursor (LoadCursor (NULL, IDC_ARROW)) ;
        

                                         // Simulate a WM_SIZE message to alter scroll bar & repaint
        

                          SendMessage (hwnd, WM_SIZE, 0, MAKELONG (cxClient, cyClient)) ;
        
                          InvalidateRect (hwnd, NULL, TRUE) ;
        
                         return 0 ;
        

           case   WM_PAINT:
        
                          hdc = BeginPaint (hwnd, &ps) ;
        
                          SetTextAlign (hdc, TA_UPDATECP) ;
        

                          si.cbSize = sizeof (SCROLLINFO) ;
        
                          si.fMask = SIF_POS ;
        
                          GetScrollInfo (hwnd, SB_VERT, &si) ;
        

                          if (plist)
        
                          {
        
                                         for (i = 0 ; i < plist->iNum ; i++)
        
                                         {
        
                   MoveToEx       (hdc, cxChar, (i - si.nPos) * cyChar, NULL) ;
        
                  TextOut        (hdc, 0, 0, plist->info[i].szFilename,
        
                   lstrlen (plist->info[i].szFilename)) ;
        
                   TextOut  (hdc, 0, 0, TEXT (": "), 2) ;
        
                   TextOutA (hdc, 0, 0, plist->info[i].szContents,
        
                  strlen (plist->info[i].szContents)) ;
        
                                         }
        
                          }
        
                          EndPaint (hwnd, &ps) ;
        
                          return 0 ;
        

           case   WM_DESTROY:
        
                          PostQuitMessage (0) ;
        
                          return 0 ;
        
    }
        
           return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}
        

BOOL CALLBACK DlgProc (    HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        
{
        
    static PARAMS params ;
        
           switch (message)
        
           {
        
           case   WM_INITDIALOG:
        
                          params.bContinue = TRUE ;
        
                          params.hwnd = hwnd ;
        

                          _beginthread (FtpThread, 0, 秏s) ;
        
                          return TRUE ;
        

           case   WM_COMMAND:
        
                          switch (LOWORD (wParam))
        
                          {
        
                          case   IDCANCEL:   // button for user to abort download
        
                                         params.bContinue = FALSE ;
        
                                       return TRUE ;
        

                          case   IDOK:      // button to make dialog box go away
        
                                         EndDialog (hwnd, 0) ;
        
                                         return TRUE ;
        
                          }
        
  }
        
           return FALSE ;
        
}
        

/*---------------------------------------------------------------------------
        
  FtpThread: Reads files from FTP server and copies them to local disk
        
-----------------------------------------------------------------------------*/
        

void FtpThread (PVOID parg)
        
{
        
           BOOL                                                        bSuccess ;
        
           HINTERNET                                   hIntSession, hFtpSession, hFind ;
        
           HWND                                                        hwndStatus, hwndButton ;
        
           PARAMS                               *      pparams ;
        
           TCHAR                                                       szBuffer [64] ;
        
           WIN32_FIND_DATA               finddata ;
        

           pparams               = parg ;
        
           hwndStatus    = GetDlgItem (pparams->hwnd, IDC_STATUS) ;
        
           hwndButton    = GetDlgItem (pparams->hwnd, IDCANCEL) ;
        

                          // Open an internet session
        
   
        
           hIntSession = InternetOpen (szAppName, INTERNET_OPEN_TYPE_PRECONFIG,
        
                                 NULL, NULL, INTERNET_FLAG_ASYNC) ;
        
           if (hIntSession == NULL)
        
           {
        
       wsprintf (szBuffer, TEXT ("InternetOpen error %i"), GetLastError ()) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, szBuffer) ;
        
                  _endthread () ;
        
           }
        

           SetWindowText (hwndStatus, TEXT ("Internet session opened...")) ;
        
                          // Check if user has pressed Cancel
        
           if (!pparams->bContinue)
        
           {
        
                  InternetCloseHandle (hIntSession) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, NULL) ;
        
                  _endthread () ;
        
           }
        

                  // Open an FTP session.
        
hFtpSession = InternetConnect (hIntSession, FTPSERVER, INTERNET_DEFAULT_FTP_PORT,
        
                             NULL, NULL, INTERNET_SERVICE_FTP, 0, 0) ;
        
          if (hFtpSession == NULL)
        
           {
        
                  InternetCloseHandle (hIntSession) ;
        
                  wsprintf (szBuffer, TEXT ("InternetConnect error %i"),
        
                                                                       GetLastError ()) ;
        
           ButtonSwitch (hwndStatus, hwndButton, szBuffer) ;
        
           _endthread () ;
        
    }
        

    SetWindowText (hwndStatus, TEXT ("FTP Session opened...")) ;
        
                          // Check if user has pressed Cancel
        
    if (!pparams->bContinue)
        
           {
        
                  InternetCloseHandle (hFtpSession) ;
        
                  InternetCloseHandle (hIntSession) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, NULL) ;
        
                  _endthread () ;
        
           }
        

                          // Set the directory
        
           bSuccess = FtpSetCurrentDirectory (hFtpSession, DIRECTORY) ;
        
           if (!bSuccess)
        
           {
        
                  InternetCloseHandle (hFtpSession) ;
        
                  InternetCloseHandle (hIntSession) ;
        
                  wsprintf (    szBuffer, TEXT ("Cannot set directory to %s"),
        
                                                                        DIRECTORY) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, szBuffer) ;
        
                  _endthread () ;
        
           }
        

           SetWindowText (hwndStatus, TEXT ("Directory found...")) ;
        
                  // Check if user has pressed Cancel
        
           if (!pparams->bContinue)
        
           {
        
                  InternetCloseHandle (hFtpSession) ;
        
                  InternetCloseHandle (hIntSession) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, NULL) ;
        
                  _endthread () ;
        
           }
        

                          // Get the first file fitting the template
        
           hFind = FtpFindFirstFile (hFtpSession, TEMPLATE, &finddata, 0, 0) ;
        
           if (hFind == NULL)
        
           {
        
                  InternetCloseHandle (hFtpSession) ;
        
                  InternetCloseHandle (hIntSession) ;
        
                  ButtonSwitch (hwndStatus, hwndButton, TEXT ("Cannot find files")) ;
        
                  _endthread () ;
        
           }
        

    do
        
           {
        
                                  // Check if user has pressed Cancel
        
            if (!pparams->bContinue)
        
                  {
        
                                 InternetCloseHandle (hFind) ;
        
                                  InternetCloseHandle (hFtpSession) ;
        
                                 InternetCloseHandle (hIntSession) ;
        
                                  ButtonSwitch (hwndStatus, hwndButton, NULL) ;
        
                                  _endthread () ;
        
                  }
        
                                  // Copy file from internet to local hard disk, but fail
        
                                  // if the file already exists locally
        

                  wsprintf (szBuffer, TEXT ("Reading file %s..."), finddata.cFileName) ;
        
                  SetWindowText (hwndStatus, szBuffer) ;
        

                  FtpGetFile (  hFtpSession,
        
               finddata.cFileName, finddata.cFileName, TRUE,
        
               FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0) ;
        
           }
        
           while (InternetFindNextFile (hFind, &finddata)) ;
        
           InternetCloseHandle (hFind) ;
        
           InternetCloseHandle (hFtpSession) ;
        
           InternetCloseHandle (hIntSession) ;
        

           ButtonSwitch (hwndStatus, hwndButton, TEXT ("Int

⌨️ 快捷键说明

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