//////////////////////////////////////////////////////////////////////
//
// Written by Michael Dunn (mdunn at inreach dot com). Copyright and all
// that stuff. Use however you like but give me credit where it's due. I'll
// know if you don't. bwa ha ha ha ha!
//
// Release history:
// December 24, 1999: Version 1.0. First release.
//
//////////////////////////////////////////////////////////////////////
// URLDownloadDlg.cpp : implementation file
//
#include "stdafx.h"
#include "URLDownload.h"
#include "URLDownloadDlg.h"
#include "BindStatusCallback.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static UINT gThreadProc ( void* pv );
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}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)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CURLDownloadDlg dialog
CURLDownloadDlg::CURLDownloadDlg(CWnd* pParent /*=NULL*/)
: CDialog(CURLDownloadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CURLDownloadDlg)
m_uTimeout = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CURLDownloadDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CURLDownloadDlg)
DDX_Control(pDX, IDC_TIMEOUT_SECS, m_editTimeout);
DDX_Control(pDX, IDC_TIMEOUT, m_btnTimeout);
DDX_Control(pDX, IDC_SPIN, m_spinner);
DDX_Control(pDX, IDC_FILE, m_editFile);
DDX_Control(pDX, IDC_ABOUT, m_btnAbout);
DDX_Control(pDX, IDC_URL, m_editURL);
DDX_Control(pDX, IDCANCEL, m_btnExit);
DDX_Control(pDX, IDC_STOP, m_btnStop);
DDX_Control(pDX, IDC_START, m_btnStart);
DDX_Control(pDX, IDC_PROGRESS, m_progress);
DDX_Control(pDX, IDC_IE_STATUS, m_stIEMsg);
DDX_Control(pDX, IDC_CUSTOM_STATUS, m_stCustomMsg);
DDX_Text(pDX, IDC_TIMEOUT_SECS, m_uTimeout);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CURLDownloadDlg, CDialog)
//{{AFX_MSG_MAP(CURLDownloadDlg)
ON_WM_SYSCOMMAND()
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
ON_BN_CLICKED(IDC_TIMEOUT, OnClickedTimeout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CURLDownloadDlg message handlers
BOOL CURLDownloadDlg::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
// Init & pre-fill some of the dlg controls.
m_spinner.SetRange ( 1, 120 );
m_progress.SetRange ( 0, 100 );
// Fill the URL editbox with "http://"
m_editURL.SetWindowText ( _T("http://") );
// Fill the file editbox with the user's MyDocs directory.
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
TCHAR szDocsDir [MAX_PATH];
if ( SUCCEEDED( SHGetSpecialFolderLocation ( NULL, CSIDL_PERSONAL,
&pidl )))
{
if ( SHGetPathFromIDList ( pidl, szDocsDir ))
{
lstrcat ( szDocsDir, _T("\\") );
m_editFile.SetWindowText ( szDocsDir );
}
if ( SUCCEEDED( SHGetMalloc ( &pMalloc )))
{
pMalloc->Free ( pidl );
pMalloc->Release();
}
}
// Set the focus to the URL edit box.
GotoDlgCtrl ( &m_editURL );
m_editURL.SetSel ( -1, -1 );
return FALSE; // return TRUE unless you set the focus to a control
}
void CURLDownloadDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
/////////////////////////////////////////////////////////////////////////////
// CURLDownloadDlg command handlers
void CURLDownloadDlg::OnOK()
{
// Do nothing - this is just here to prevent the dlg from closing if
// the user hits the Enter key.
}
void CURLDownloadDlg::OnStart()
{
CWinThread* pWorkerThread;
UpdateData();
if ( m_editURL.GetWindowTextLength() == 0 )
{
AfxMessageBox ( _T("Please enter a URL.") );
return;
}
if ( m_editURL.GetWindowTextLength() == 0 )
{
AfxMessageBox ( _T("Please enter a filename.") );
return;
}
// Create our worker thread. It won't start until we disable all of the
// dialog controls.
pWorkerThread = AfxBeginThread ( gThreadProc, this,
THREAD_PRIORITY_NORMAL, 0,
CREATE_SUSPENDED );
// Note: Yeah I know that it's BAD to pass a CWnd object between threads.
// I forgot about that rule when I wrote the above call, and it turns out
// that I got lucky and it works. All the stuff the worker thread does
// involves just sending messages to window handles. Since accessing the
// data member CWnd::m_hWnd is safe to do across threads, nothing ever
// asserted to alert me of this mistake.
// Since I have finished this sample app and just now noticed this mistake,
// I;m gonna be lazy and not fix it. :D
if ( NULL != pWorkerThread )
{
g_fAbortDownload = 0;
m_editURL. EnableWindow ( FALSE );
m_editFile. EnableWindow ( FALSE );
m_editTimeout.EnableWindow ( FALSE );
m_btnStart. EnableWindow ( FALSE );
m_btnStop. EnableWindow ();
m_btnExit. EnableWindow ( FALSE );
m_btnAbout. EnableWindow ( FALSE );
m_btnTimeout. EnableWindow ( FALSE );
m_spinner. EnableWindow ( FALSE );
GotoDlgCtrl ( &m_btnStop );
// Kick off the download!
pWorkerThread->ResumeThread();
}
else
{
AfxMessageBox ( _T("Couldn't create worker thread!"), MB_ICONERROR );
}
}
void CURLDownloadDlg::OnStop()
{
InterlockedExchange ( &g_fAbortDownload, 1 );
}
void CURLDownloadDlg::OnAbout()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CURLDownloadDlg message handlers
// Handler for BN_CLICKED from the "Use time limit" checkbox.
void CURLDownloadDlg::OnClickedTimeout()
{
UpdateTimeoutCtrls();
}
// UpdateTimeoutCtrls(): Enabl
没有合适的资源?快使用搜索试试~ 我知道了~
http下载器(URLDownloadToFile )
共29个文件
h:5个
cpp:4个
obj:4个
4星 · 超过85%的资源 需积分: 31 261 下载量 180 浏览量
2009-12-22
09:57:17
上传
评论
收藏 3.7MB RAR 举报
温馨提示
http下载,实现 目标另存为 的效果。可以自行编辑下载路径,可显示下载文件的大小,当前已下载大小,下载时间,以及下载进度条。该工程在vs2003中编译、运行成功。该资源来自网络,就不要分了。
资源推荐
资源详情
资源评论
收起资源包目录
URLDownload.rar (29个子文件)
URLDownload.rc 7KB
StdAfx.cpp 641B
resource.h 1KB
URLDownload.dsp 7KB
BindStatusCallback.h 3KB
URLDownload.cpp 2KB
URLDownload.clw 2KB
BindStatusCallback.cpp 3KB
URLDownload.suo 12KB
URLDownload.ncb 51KB
Debug
URLDownload.pch 10.25MB
vc70.idb 323KB
URLDownload.res 4KB
vc70.pdb 1004KB
BuildLog.htm 818B
URLDownload.obj 18KB
URLDownload.pdb 2.72MB
StdAfx.obj 275KB
URLDownloadDlg.obj 53KB
URLDownload.exe 88KB
BindStatusCallback.obj 21KB
StdAfx.h 1KB
URLDownload.sln 1KB
res
URLDownload.ico 1KB
URLDownload.rc2 403B
URLDownloadDlg.h 2KB
URLDownloadDlg.cpp 11KB
URLDownload.vcproj 13KB
URLDownload.h 2KB
共 29 条
- 1
小秀才
- 粉丝: 9
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页