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

📄 netdownmtrdlg.cpp

📁 多线程下载的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// NetDownMTRDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NetDownMTR.h"
#include "NetDownMTRDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetDownMTRDlg dialog

CNetDownMTRDlg::CNetDownMTRDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNetDownMTRDlg::IDD, pParent)
	, m_pDownloadMTR ( NULL )
	, m_bDownloadIsStart ( FALSE )
	, m_bFileNameGetFocus ( FALSE )
{
	//{{AFX_DATA_INIT(CNetDownMTRDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_Ary_DownloadNotifyPara.SetSize ( 0, 10*sizeof(t_DownloadNotifyPara) );
}

void CNetDownMTRDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNetDownMTRDlg)
	DDX_Control(pDX, IDC_PROGRESS1, m_progress);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNetDownMTRDlg, CDialog)
	//{{AFX_MSG_MAP(CNetDownMTRDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_Browse, OnBUTTONBrowse)
	ON_WM_DESTROY()
	ON_EN_CHANGE(IDC_EDIT_RemoteFileURL, OnChangeEDITRemoteFileURL)
	ON_BN_CLICKED(IDC_BUTTON_Stop, OnBUTTONStop)
	ON_EN_KILLFOCUS(IDC_EDIT_FileName, OnKillfocusEDITFileName)
	ON_EN_SETFOCUS(IDC_EDIT_FileName, OnSetfocusEDITFileName)
	ON_MESSAGE(WM_SHOWLOG,OnWM_SHOWLOG)
	ON_MESSAGE(WM_DOWNLOAD_NOTIFY,OnWM_DOWNLOAD_NOTIFY)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNetDownMTRDlg message handlers

BOOL CNetDownMTRDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	Set_RecvLogMsgHwnd ( GetSafeHwnd() );
	Log ( L_VERBOSE, "\r\n%s", NOTE_DownloadMTR );

	SetCtrlValue ();
	EnableSomeWindow ();
	
	BOOL success = m_OleTarget.Register(this);
    if(!success )
		MessageBox("Ole Register Drop Target Failed");             
	
	m_OleTarget.SetParent(this);

	// 总在最前
#ifndef _DEBUG
	CRect rect;
	GetWindowRect(&rect);
	SetWindowPos(&wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOMOVE); 
#endif

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNetDownMTRDlg::OnSysCommand(UINT nID,LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CNetDownMTRDlg::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 CNetDownMTRDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void Callback_DownloadNotify ( t_DownloadNotifyPara *pDownloadNotifyPara, WPARAM wParam )
{
	CNetDownMTRDlg *pNetDownMTRDlg = (CNetDownMTRDlg*)wParam;
	ASSERT ( pNetDownMTRDlg );
	pNetDownMTRDlg->Add_DownloadNotifyPara ( pDownloadNotifyPara );
	pNetDownMTRDlg->PostMessage ( WM_DOWNLOAD_NOTIFY, WPARAM(NULL), LPARAM(NULL) );
}

LRESULT CNetDownMTRDlg::OnWM_DOWNLOAD_NOTIFY(WPARAM wParam, LPARAM lParam)
{
	t_Ary_DownloadNotifyPara Ary_DownloadNotifyPara;
	Get_Ary_DownloadNotifyPara ( Ary_DownloadNotifyPara );
	for ( int i=0; i<Ary_DownloadNotifyPara.GetSize(); i++ )
	{
		t_DownloadNotifyPara &DownloadNotifyPara = Ary_DownloadNotifyPara.GetAt (i);
		Callback_DownloadNotify ( &DownloadNotifyPara );
	}
	return TRUE;
}

void CNetDownMTRDlg::Callback_DownloadNotify(t_DownloadNotifyPara *pDownloadNotifyPara)
{
	ASSERT ( pDownloadNotifyPara );
	CString csStatus;
	switch ( pDownloadNotifyPara->nNotityType )
	{
	case NOTIFY_TYPE_GOT_REMOTE_FILENAME:
		{
			OutStatusString ( pDownloadNotifyPara->nIndex, (LPCTSTR)pDownloadNotifyPara->lpNotifyData );
			break;
		}
	case NOTIFY_TYPE_GOT_REMOTE_FILESIZE:
		{
			int nFileSize = (int)pDownloadNotifyPara->lpNotifyData;
			csStatus.Format ( "File size is : %s bytes", FormatFileSize(nFileSize) );
			OutStatusString ( pDownloadNotifyPara->nIndex, csStatus );
			ASSERT ( nFileSize == ( (CDownloadMTR*)pDownloadNotifyPara->pDownloadMTR )->Get_FileTotaleSize() );
			m_progress.SetRange32 ( 0, nFileSize );
			break;
		}
	case NOTIFY_TYPE_START_DOWNLOAD:
		{
			OutStatusString ( pDownloadNotifyPara->nIndex, _T("Start download") );
			break;
		}
	case NOTIFY_TYPE_END_DOWNLOAD:
		{
			m_bDownloadIsStart = FALSE;
			EnableSomeWindow ();
			OutStatusString ( pDownloadNotifyPara->nIndex, _T("End download") );
			ENUM_DOWNLOAD_RESULT eDownloadResult = (ENUM_DOWNLOAD_RESULT)(int)pDownloadNotifyPara->lpNotifyData;
			CString csMsg, csElapseTime;
			ASSERT ( pDownloadNotifyPara->pDownloadMTR );
			csElapseTime.Format ( "%d ms", ( (CDownloadMTR*)pDownloadNotifyPara->pDownloadMTR )->GetDownloadElapsedTime() );
			if ( eDownloadResult == ENUM_DOWNLOAD_RESULT_SUCCESS )
			{
				csMsg = "Download successfully";
			}
			else if ( eDownloadResult == ENUM_DOWNLOAD_RESULT_FAILED )
			{
				csMsg = "Download failed";
			}
			else if ( eDownloadResult == ENUM_DOWNLOAD_RESULT_CANCEL )
			{
				csMsg = "User cancel download";
			}
			else
			{
				ASSERT ( FALSE );
			}
			csMsg += ", Elapse time : " + csElapseTime;
			Log ( (eDownloadResult==ENUM_DOWNLOAD_RESULT_SUCCESS)?L_NORMAL:L_ERROR, "%s", csMsg );
			AfxMessageBox ( csMsg, (eDownloadResult==ENUM_DOWNLOAD_RESULT_SUCCESS)?MB_ICONINFORMATION:MB_ICONWARNING );

			break;
		}
	case NOTIFY_TYPE_WILL_DOWNLOAD_SIZE:
		{
			csStatus.Format ( "Will download size is : %d bytes", (int)pDownloadNotifyPara->lpNotifyData );
			OutStatusString ( pDownloadNotifyPara->nIndex, csStatus );
			break;
		}
	case NOTIFY_TYPE_THREAD_DOWNLOADED_SIZE:
		{
			csStatus.Format ( "Downloaded size is : %d bytes", (int)pDownloadNotifyPara->lpNotifyData );
			OutStatusString ( pDownloadNotifyPara->nIndex, csStatus );

⌨️ 快捷键说明

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