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

📄 20090304.txt

📁    下载整个网站的源代码工具
💻 TXT
📖 第 1 页 / 共 3 页
字号:
/* 下载整个网站的源代码工具   */

   
// CodeProjectDlg.cpp : implementation file    
//    
   

   
#include "stdafx.h"    
#include "CodeProject.h"    
#include "CodeProjectDlg.h"    
#include "DlgExplain.h"    
   
#ifdef _DEBUG    
#define new DEBUG_NEW    
#undef THIS_FILE    
static char THIS_FILE[] = __FILE__;   
#endif    
   
#define WM_USER_DOWNSTATUS      (WM_USER + 101)    
#define WM_USER_DOWNCOMPLETE    (WM_USER + 102)    
   
/////////////////////////////////////////////////////////////////////////////    
// CCodeProjectDlg dialog    
bool DownloadHtml(CInternetSession &session, CString &strURL, CString &outStr)   
{   
    //K 下载指定的网页到一个字符串中    
    CString sHeader = _T("Accept:*/*\r\n");   
    DWORD dwFlags = INTERNET_FLAG_DONT_CACHE |   
                    INTERNET_FLAG_TRANSFER_BINARY |   
                    INTERNET_FLAG_EXISTING_CONNECT |   
                    INTERNET_FLAG_RELOAD;   
    int nRead;   
    char buffer[1024];   
       
    try   
    {   
        if(strURL.Left(7) != _T("http://")) strURL = _T("http://") + strURL;   
        CHttpFile *pHttpFile = (CHttpFile*)session.OpenURL(strURL, 1, dwFlags, sHeader, -1L);   
        if(pHttpFile)   
        {   
            do   
            {   
                nRead = pHttpFile->Read(buffer, 1023);   
                if(nRead != 0)   
                {   
                    buffer[nRead] = 0;   
                    outStr += buffer;   
                }   
            } while (nRead != 0);   
            delete pHttpFile;   
   
        }   
        else   
        {   
            AfxMessageBox(_T("建立连接失败:") + strURL);   
            return false;   
        }   
    }   
    catch (CInternetException *pEx)   
    {   
        AfxMessageBox(_T("访问网址时出现异常:") + strURL);   
        pEx->Delete();   
        return false;   
    }   
    return true;   
}   
   
bool ConfirmDir(CString &strDir)   
{   
    //K 确认目录,如果不存在就创建它    
    if (-1 == _taccess(strDir, 0))   
        if (!::CreateDirectory(strDir, NULL))   
        {   
            AfxMessageBox(_T("创建文件夹失败!") + strDir);   
            return false;   
        }   
    return true;   
}   
   
bool DownloadFile(CInternetSession &session, CString &strURL, CString &strFileName)   
{   
    //K 下载指定的文件    
    CString sHeader = _T("Accept:*/*\r\n");   
    DWORD dwFlags = INTERNET_FLAG_DONT_CACHE |   
                    INTERNET_FLAG_TRANSFER_BINARY |   
                    INTERNET_FLAG_EXISTING_CONNECT |   
                    INTERNET_FLAG_RELOAD;   
    int nRead;   
    char buffer[1024];   
    CHttpFile *pHttpFile = NULL;   
    CFile *pFile = NULL;   
   
    try   
    {   
        if(strURL.Left(7) != _T("http://")) strURL = _T("http://") + strURL;   
        pHttpFile = (CHttpFile*)session.OpenURL(strURL, 1, dwFlags, sHeader, -1L);   
        if(pHttpFile)   
        {   
            pFile = new CFile;   
            pFile->Open(strFileName, CFile::modeWrite | CFile::modeCreate);   
            do   
            {   
                nRead = pHttpFile->Read(buffer, 1023);   
                if(nRead != 0)   
                {   
                    buffer[nRead] = 0;   
                    pFile->Write(buffer, nRead);   
                }   
            } while (nRead != 0);   
            delete pHttpFile;   
            pFile->Close();   
            delete pFile;   
        }   
        else   
        {   
            AfxMessageBox(_T("建立连接失败:") + strURL);   
            return false;   
        }   
    }   
    catch (CInternetException *pEx)   
    {   
        AfxMessageBox(_T("访问网址时出现异常:") + strURL);   
        pEx->Delete();   
        if (NULL != pHttpFile) delete pHttpFile;   
        if (NULL != pFile) delete pFile;   
        return false;   
    }   
    catch (CFileException * pFEx)   
    {   
        AfxMessageBox(_T("写文件时出现异常!") + strURL + _T("->") + strFileName);   
        pFEx->Delete();   
        if (NULL != pHttpFile) delete pHttpFile;   
        if (NULL != pFile) delete pFile;   
        return false;   
    }   
    return true;   
}   
   
bool SaveStr2File(CString &inStr, CString &strFileName)   
{   
    //K 将字符串中的内容保存为文件    
    CFile *pFile = new CFile;   
    pFile->Open(strFileName, CFile::modeWrite | CFile::modeCreate);   
    inStr.FreeExtra();   
    long lStrLen = inStr.GetLength() * sizeof(TCHAR);   
    pFile->Write((void*)inStr.GetBuffer(lStrLen), lStrLen);   
    pFile->Close();   
    delete pFile;   
    return true;   
}   
   
CString CCodeProjectDlg::m_strTargetDir;   
CArray<CSTRING, CString> CCodeProjectDlg::m_aryDownloadItem;   
CArray<CSTRING, CString> CCodeProjectDlg::m_aryDownloadItemName;   
   
CCodeProjectDlg::CCodeProjectDlg(CWnd* pParent /*=NULL*/)   
    : CDialog(CCodeProjectDlg::IDD, pParent)   
{   
    //{{AFX_DATA_INIT(CCodeProjectDlg)    
        // NOTE: the ClassWizard will add member initialization here    
    //}}AFX_DATA_INIT    
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32    
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);   
}   
   
void CCodeProjectDlg::DoDataExchange(CDataExchange* pDX)   
{   
    CDialog::DoDataExchange(pDX);   
    //{{AFX_DATA_MAP(CCodeProjectDlg)    
    DDX_Control(pDX, IDOK, m_btnOK);   
    DDX_Control(pDX, IDC_EDIT1, m_editStatus);   
    DDX_Control(pDX, IDC_LIST, m_list);   
    DDX_Control(pDX, IDC_EDIT_TargetDir, m_editTargetDir);   
    //}}AFX_DATA_MAP    
}   
   
BEGIN_MESSAGE_MAP(CCodeProjectDlg, CDialog)   
    //{{AFX_MSG_MAP(CCodeProjectDlg)    
    ON_WM_PAINT()   
    ON_WM_QUERYDRAGICON()   
    ON_BN_CLICKED(IDC_STATIC_WEB, OnStaticWeb)   
    ON_MESSAGE(WM_USER_DOWNSTATUS, OnDownStatus)   
    ON_MESSAGE(WM_USER_DOWNCOMPLETE, OnDownComplete)   
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)   
    //}}AFX_MSG_MAP    
END_MESSAGE_MAP()   
   
/////////////////////////////////////////////////////////////////////////////    
// CCodeProjectDlg message handlers    
   
BOOL CCodeProjectDlg::OnInitDialog()   
{   
    CDialog::OnInitDialog();   
   
    // Set the icon for this dialog.  The framework does this automatically    
    //  when the application's main window is not a dialog    
    SetIcon(m_hIcon, TRUE);         // Set big icon    
    SetIcon(m_hIcon, FALSE);        // Set small icon    
       
    // TODO: Add extra initialization here    
    CString strItem[] = {   
        _T(".NET -> Managed C++"),   
        _T(".NET -> SOAP and XML"),   
        _T(".NET -> C++ Web Services"),   
        _T("MFC Controls -> Button Controls"),   
        _T("MFC Controls -> Dialog & Windows"),   
        _T("MFC Controls -> Combo & List Boxes"),   
        _T("MFC Controls -> Menus"),   
        _T("MFC Controls -> Toolbars & Docking Windows"),   
        _T("MFC Controls -> Status Bar"),   
        _T("MFC Controls -> Edit Controls"),   
        _T("MFC Controls -> List Controls"),   
        _T("MFC Controls -> Tree Controls"),   
        _T("MFC Controls -> Tab Controls"),   
        _T("MFC Controls -> Property Sheets"),   
        _T("MFC Controls -> Rich Edit Controls"),   
        _T("MFC Controls -> Splitter Windows"),   
        _T("MFC Controls -> Static Controls"),   
        _T("MFC Controls -> Miscellaneous Controls"),   
        _T("General - > COM/DCOM/COM+"),   
        _T("General - > C++/MFC"),   
        _T("General - > Clipboard"),   
        _T("General - > Doc/View"),   
        _T("General - > Debug tips"),   
        _T("General - > Database"),   
        _T("General - > Dlls"),   
        _T("General - > Files & Folders"),   
        _T("General - > Internet & Network"),   
        _T("General - > Macros and Add-ins"),   
        _T("General - > Printing"),   
        _T("General - > Samples"),   
        _T("General - > String"),   
        _T("General - > System"),   
        _T("General - > Threads, Processes & IPC"),   
        _T("General - > Programming tips"),   
        _T("General - > Free Tools"),   
        _T("General - > Shell Programming"),   
        _T("General - > Date & Time"),   
        _T("General - > WinHelp/HTMLHelp"),   
        _T("Libraries - > ATL"),   
        _T("Libraries - > WTL"),   
        _T("Libraries - > STL"),   
        _T("Libraries - > Libraries & Projects"),   
        _T("MultiMedia - > Bitmaps & Palettes"),   
        _T("MultiMedia - > Audio & Video"),   
        _T("MultiMedia - > DirectX"),   
        _T("MultiMedia - > OpenGL"),   
        _T("MultiMedia - > Fonts & GDI"),   
        _T("MultiMedia - > GDI+"),   
        _T("Platforms - > Win32/SDK"),   
        _T("Platforms - > Windows 2000/XP"),   
        _T("Platforms - > CE/Embedded"),   
        _T("Web/Scripting - > ISAPI")   
    };   
    CString strItemUrl[] = {   
        _T("http://www.codeproject.com/managedcpp"),   
        _T("http://www.codeproject.com/soap"),   
        _T("http://www.codeproject.com/webservices"),   
        _T("http://www.codeproject.com/buttonctrl"),   
        _T("http://www.codeproject.com/dialog"),   
        _T("http://www.codeproject.com/combobox"),   
        _T("http://www.codeproject.com/menu"),   
        _T("http://www.codeproject.com/docking"),   
        _T("http://www.codeproject.com/statusbar"),   
        _T("http://www.codeproject.com/editctrl"),   
        _T("http://www.codeproject.com/listctrl"),   
        _T("http://www.codeproject.com/treectrl"),   
        _T("http://www.codeproject.com/tabctrl"),   
        _T("http://www.codeproject.com/property"),   
        _T("http://www.codeproject.com/richedit"),   
        _T("http://www.codeproject.com/splitter"),   
        _T("http://www.codeproject.com/staticctrl"),   
        _T("http://www.codeproject.com/miscctrl"),   
        _T("http://www.codeproject.com/com"),   
        _T("http://www.codeproject.com/cpp"),   
        _T("http://www.codeproject.com/clipboard"),   
        _T("http://www.codeproject.com/docview"),   
        _T("http://www.codeproject.com/debug"),   
        _T("http://www.codeproject.com/database"),   
        _T("http://www.codeproject.com/dll"),   
        _T("http://www.codeproject.com/file"),   
        _T("http://www.codeproject.com/internet"),   
        _T("http://www.codeproject.com/macro"),   
        _T("http://www.codeproject.com/printing"),   
        _T("http://www.codeproject.com/samples"),   
        _T("http://www.codeproject.com/string"),   
        _T("http://www.codeproject.com/system"),   
        _T("http://www.codeproject.com/threads"),   
        _T("http://www.codeproject.com/tips"),   
        _T("http://www.codeproject.com/tools"),   
        _T("http://www.codeproject.com/shell"),   
        _T("http://www.codeproject.com/datetime"),   
        _T("http://www.codeproject.com/winhelp"),   
        _T("http://www.codeproject.com/atl"),   
        _T("http://www.codeproject.com/wtl"),   
        _T("http://www.codeproject.com/vcpp/stl"),   
        _T("http://www.codeproject.com/library"),   
        _T("http://www.codeproject.com/bitmap"),   
        _T("http://www.codeproject.com/audio"),   
        _T("http://www.codeproject.com/directx"),   
        _T("http://www.codeproject.com/opengl"),   
        _T("http://www.codeproject.com/gdi"),   
        _T("http://www.codeproject.com/gdiplus"),   
        _T("http://www.codeproject.com/win32"),   
        _T("http://www.codeproject.com/w2k"),   
        _T("http://www.codeproject.com/ce"),   
        _T("http://www.codeproject.com/isapi")   
    };   
       
    ListView_SetExtendedListViewStyle(m_list.m_hWnd, LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP|LVS_EX_FLATSB|LVS_EX_GRIDLINES|LVS_EX_CHECKBOXES);   
    m_list.InsertColumn(0, _T("下载项目"), LVCFMT_CENTER, 300);   
    m_list.InsertColumn(1, _T("URL"), LVCFMT_LEFT, 300);   
   
    //K 显示可选的下载项目    
    for(int i = 0; i < sizeof(strItem) / sizeof(CString); ++i)   
    {   
        m_list.InsertItem(i, strItem[i]);   
        m_list.SetItemText(i, 1, strItemUrl[i]);   
    }   
       
    m_editTargetDir.SetWindowText(_T("C:\\CodeProject"));   
   
    m_bWorking = FALSE;   
    //m_btnOK.EnableWindow(FALSE);    
   
    return TRUE;  // return TRUE  unless you set the focus to a control    
}   
   
// If you add a minimize button to your dialog, you will need the code below    
//  to draw the icon.  For MFC applications using the document/view model,    
//  this is automatically done for you by the framework.    
   
void CCodeProjectDlg::OnPaint()    
{   
    if (IsIconic())   
    {   
        CPaintDC dc(this); // device context for painting    
   
        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);   
   
        // Center icon in client rectangle    
        int cxIcon = GetSystemMetrics(SM_CXICON);   
        int cyIcon = GetSystemMetrics(SM_CYICON);   
        CRect rect;   
        GetClientRect(&rect);   
        int x = (rect.Width() - cxIcon + 1) / 2;   
        int y = (rect.Height() - cyIcon + 1) / 2;   
   
        // Draw the icon    
        dc.DrawIcon(x, y, m_hIcon);   
    }   
    else   
    {   
        CDialog::OnPaint();   
    }   
}   
   
// The system calls this to obtain the cursor to display while the user drags    
//  the minimized window.    
HCURSOR CCodeProjectDlg::OnQueryDragIcon()   
{   
    return (HCURSOR) m_hIcon;   
}   
   
void CCodeProjectDlg::OnOK()    
{   
    m_btnOK.EnableWindow(FALSE);   
    m_bWorking = TRUE;   
   
    //K 取得输入的目标路径    
    m_editTargetDir.GetWindowText(m_strTargetDir);   
    m_strTargetDir.Replace(_T("\\"), _T("\\\\"));   
    if (m_strTargetDir.Right(2) != _T("\\\\")) m_strTargetDir += _T("\\\\");   
   
    ConfirmDir(m_strTargetDir);   
   
    //K 取得到下载的项目    
    m_aryDownloadItem.RemoveAll();   
    m_aryDownloadItemName.RemoveAll();   
    int iItemNum = m_list.GetItemCount();   
    for (int i = 0; i < iItemNum; ++i)   
    {   
        if (ListView_GetCheckState(m_list.m_hWnd, i))   
        {   
            m_aryDownloadItemName.Add(m_list.GetItemText(i,0));   
            m_aryDownloadItem.Add(m_list.GetItemText(i,1));   
        }   
    }   
   
    m_editStatus.SetWindowText(_T(""));   

⌨️ 快捷键说明

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