亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dlgdownload.cpp

?? 本程序是VC為平臺開發的股票資訊系統
?? CPP
字號:
// DlgDownload.cpp : implementation file
//

#include "stdafx.h"
#include "stockrefer.h"
#include "DlgDownload.h"

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

const UINT WM_HTTPDOWNLOAD_THREAD_FINISHED = WM_APP + 1;

/////////////////////////////////////////////////////////////////////////////
// CDlgDownload dialog
IMPLEMENT_DYNAMIC(CDlgDownload, CDialog);

CDlgDownload::CDlgDownload(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgDownload::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgDownload)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hInternetSession = NULL;
	m_hHttpConnection = NULL;
	m_hHttpFile = NULL;
	m_bAbort = FALSE;
	m_bSafeToClose = FALSE;
	m_pThread = NULL;
}


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


BEGIN_MESSAGE_MAP(CDlgDownload, CDialog)
	//{{AFX_MSG_MAP(CDlgDownload)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_HTTPDOWNLOAD_THREAD_FINISHED, OnThreadFinished)
END_MESSAGE_MAP()

LRESULT CDlgDownload::OnThreadFinished(WPARAM wParam, LPARAM /*lParam*/)
{
	//It's now safe to close since the thread has signaled us
	m_bSafeToClose = TRUE;
	//Stop the animation
	m_avi.Stop();
	//If an error occured display the message box
	if (m_bAbort)
		EndDialog(IDCANCEL);
	else if (wParam)
	{
		AfxMessageBox(m_sError);
		EndDialog(IDCANCEL);
	}
	else
		EndDialog(IDOK);
	
	return 0L;
}

/////////////////////////////////////////////////////////////////////////////
// CDlgDownload message handlers

BOOL CDlgDownload::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	//Setup the animation control
	m_avi.Open(IDR_HTTPDOWNLOAD);
	
	//Validate the URL
	ASSERT(m_sURLToDownload.GetLength()); //Did you forget to specify the file to download
	if (!AfxParseURL(m_sURLToDownload, m_dwServiceType, m_sServer, m_sObject, m_nPort))
	{
		//Try sticking "http://" before it
		m_sURLToDownload = _T("http://") + m_sURLToDownload;
		if (!AfxParseURL(m_sURLToDownload, m_dwServiceType, m_sServer, m_sObject, m_nPort))
		{
			TRACE(_T("Failed to parse the URL: %s\n"), m_sURLToDownload);
			EndDialog(IDCANCEL);
			return TRUE;
		}
	}
	
	//Check to see if the file we are downloading to exists and if
	//it does, then ask the user if they were it overwritten
	CFileStatus fs;
	ASSERT(m_sFileToDownloadInto.GetLength());
	if (CFile::GetStatus(m_sFileToDownloadInto, fs) &&
		m_sFileToDownloadInto.Find(_T("edudat_.udb")) == -1)
	{
		CString sMsg;
		AfxFormatString1(sMsg, IDS_HTTPDOWNLOAD_OK_TO_OVERWRITE, m_sFileToDownloadInto);
		if (AfxMessageBox(sMsg, MB_YESNO) != IDYES)
		{
			TRACE(_T("Failed to confirm file overwrite, download aborted\n"));
			EndDialog(IDCANCEL);
			return TRUE;
		}
	}
	
	//Try and open the file we will download into
	if (!m_FileToWrite.Open(m_sFileToDownloadInto, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite))
	{
		TRACE(_T("Failed to open the file to download into, Error:%d\n"), GetLastError());
		CString sError;
		sError.Format(_T("%d"), ::GetLastError());
		CString sMsg;
		AfxFormatString1(sMsg, IDS_HTTPDOWNLOAD_FAIL_FILE_OPEN, sError);
		AfxMessageBox(sMsg);
		EndDialog(IDCANCEL);
		return TRUE;
	}
	
	//Pull out just the filename component
	int nSlash = m_sObject.ReverseFind(_T('/'));
	if (nSlash == -1)
		nSlash = m_sObject.ReverseFind(_T('\\'));
	if (nSlash != -1 && m_sObject.GetLength() > 1)
		m_sFilename = m_sObject.Right(m_sObject.GetLength() - nSlash - 1);
	else
		m_sFilename = m_sObject;
	
	//Set the file status text
	CString sFileStatus;
	ASSERT(m_sObject.GetLength());
	ASSERT(m_sServer.GetLength());
	if(m_sFilename.Find(_T("edudat.udb")) != -1)
		AfxFormatString2(sFileStatus, IDS_HTTPDOWNLOAD_FILESTATUS, _T("搜索程序"), m_sServer);
	else
		AfxFormatString2(sFileStatus, IDS_HTTPDOWNLOAD_FILESTATUS, m_sFilename, m_sServer);
	
	//Spin off the background thread which will do the actual downloading
	m_pThread = AfxBeginThread(_DownloadThread, this, THREAD_PRIORITY_NORMAL, CREATE_SUSPENDED);
	if (m_pThread == NULL)
	{
		TRACE(_T("Failed to create download thread, dialog is aborting\n"));
		EndDialog(IDCANCEL);
		return TRUE;
	}
	m_pThread->m_bAutoDelete = FALSE;
	m_pThread->ResumeThread();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

UINT CDlgDownload::_DownloadThread(LPVOID pParam)
{
	//Convert from the SDK world to the C++ world
	CDlgDownload* pDlg = (CDlgDownload*) pParam;
	ASSERT(pDlg);
	ASSERT(pDlg->IsKindOf(RUNTIME_CLASS(CDlgDownload)));
	pDlg->DownloadThread();
	return 0;
}

void CDlgDownload::SetProgressRange(DWORD dwFileSize)
{
	m_progress.SetRange(0, (short)((dwFileSize+512)/1024));
}

void CDlgDownload::SetProgress(DWORD dwBytesRead)
{
	m_progress.SetPos(dwBytesRead/1024);
}

void CDlgDownload::PlayAnimation()
{
	m_avi.Play(0, (UINT)-1, (UINT)-1);
}

void CDlgDownload::HandleThreadErrorWithLastError(UINT nIDError, DWORD dwLastError)
{
	//Form the error string to report
	CString sError;
	if (dwLastError)
		sError.Format(_T("%d"), dwLastError);
	else
		sError.Format(_T("%d"), ::GetLastError());
	AfxFormatString1(m_sError, nIDError, sError);
	
	//Delete the file being downloaded to if it is present
	m_FileToWrite.Close();
	::DeleteFile(m_sFileToDownloadInto);
	
	PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED, 1);
}

void CDlgDownload::HandleThreadError(UINT nIDError)
{
	m_sError.LoadString(nIDError);
	PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED, 1);
}

void CDlgDownload::DownloadThread()
{
	//Create the Internet session handle
	ASSERT(m_hInternetSession == NULL);
	m_hInternetSession = ::InternetOpen(_T("USER"),INTERNET_OPEN_TYPE_PROXY,m_sProxy,m_sPort,0);   
	
	if (m_hInternetSession == NULL)
	{
		TRACE(_T("Failed in call to InternetOpen, Error:%d\n"), ::GetLastError());
		HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_GENERIC_ERROR);
		return;
	}
	
	//Should we exit the thread
	if (m_bAbort)
	{
		PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED);
		return;
	}  
	
	//Make the connection to the HTTP server          
	ASSERT(m_hHttpConnection == NULL);
	if (m_sUserName.GetLength())
		m_hHttpConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, m_sUserName, 
		m_sPassword, m_dwServiceType, 0, (DWORD) this);
	else
		m_hHttpConnection = ::InternetConnect(m_hInternetSession, m_sServer, m_nPort, NULL, 
		NULL, m_dwServiceType, 0, (DWORD) this);
	if (m_hHttpConnection == NULL)
	{
		TRACE(_T("Failed in call to InternetConnect, Error:%d\n"), ::GetLastError());
		HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER);
		return;
	}
	
	//Should we exit the thread
	if (m_bAbort)
	{
		PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED);
		return;
	}  
	
	//Start the animation to signify that the download is taking place
	PlayAnimation();
	
	//Issue the request to read the file
	LPCTSTR ppszAcceptTypes[2];
	ppszAcceptTypes[0] = _T("*/*");  //We support accepting any mime file type since this is a simple download of a file
	ppszAcceptTypes[1] = NULL;
	ASSERT(m_hHttpFile == NULL);
	m_hHttpFile = HttpOpenRequest(m_hHttpConnection, NULL, m_sObject, NULL, NULL, ppszAcceptTypes, INTERNET_FLAG_RELOAD | 
		INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_KEEP_CONNECTION, (DWORD) this);
	if (m_hHttpFile == NULL)
	{
		TRACE(_T("Failed in call to HttpOpenRequest, Error:%d\n"), ::GetLastError());
		HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER);
		return;
	}

	//Should we exit the thread
	if (m_bAbort)
	{
		PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED);
		return;
	}  

	//label used to jump to if we need to resend the request
	resend:

	//Issue the request
	BOOL bSend = ::HttpSendRequest(m_hHttpFile, NULL, 0, NULL, 0);
	if (!bSend)
	{
		TRACE(_T("Failed in call to HttpSendRequest, Error:%d\n"), ::GetLastError());
		HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER);
		return;
	}

	//Check the HTTP status code
	TCHAR szStatusCode[32];
	DWORD dwInfoSize = 32;
	if (!HttpQueryInfo(m_hHttpFile, HTTP_QUERY_STATUS_CODE, szStatusCode, &dwInfoSize, NULL))
	{
		TRACE(_T("Failed in call to HttpQueryInfo for HTTP query status code, Error:%d\n"), ::GetLastError());
		HandleThreadError(IDS_HTTPDOWNLOAD_INVALID_SERVER_RESPONSE);
		return;
	}
	else
	{	
		long nStatusCode = _ttol(szStatusCode);
		//Handle any authentication errors
		if (nStatusCode == HTTP_STATUS_PROXY_AUTH_REQ || nStatusCode == HTTP_STATUS_DENIED)
		{
			// We have to read all outstanding data on the Internet handle
			// before we can resubmit request. Just discard the data.
			char szData[51];
			DWORD dwSize;
			do
			{
				::InternetReadFile(m_hHttpFile, (LPVOID)szData, 50, &dwSize);
			}
			while (dwSize != 0);

			//Bring up the standard authentication dialog
			if (::InternetErrorDlg(GetSafeHwnd(), m_hHttpFile, ERROR_INTERNET_INCORRECT_PASSWORD, FLAGS_ERROR_UI_FILTER_FOR_ERRORS |
				FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS, NULL) == ERROR_INTERNET_FORCE_RETRY)
			goto resend;
		}
  		else if (nStatusCode != HTTP_STATUS_OK)
		{
			TRACE(_T("Failed to retrieve a HTTP 200 status, Status Code:%d\n"), nStatusCode);
			HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_INVALID_HTTP_RESPONSE, nStatusCode);
			return;
		}
	}

	// Get the length of the file.            
	TCHAR szContentLength[32];
	dwInfoSize = 32;
	DWORD dwFileSize = 0;
	BOOL bGotFileSize = FALSE;
	if (::HttpQueryInfo(m_hHttpFile, HTTP_QUERY_CONTENT_LENGTH, szContentLength, &dwInfoSize, NULL))
	{
		//Set the progress control range
		bGotFileSize = TRUE;
		dwFileSize = (DWORD) _ttol(szContentLength);
		SetProgressRange(dwFileSize);
	}

	//Now do the actual read of the file
	DWORD dwBytesRead = 0;
	char szReadBuf[1024];
	DWORD dwBytesToRead = 1024;
	DWORD dwTotalBytesRead = 0;
	DWORD dwLastPercentage = 0;
	do
	{
		if (!::InternetReadFile(m_hHttpFile, szReadBuf, dwBytesToRead, &dwBytesRead))
		{
			TRACE(_T("Failed in call to InternetReadFile, Error:%d\n"), ::GetLastError());
			HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_ERROR_READFILE);
			return;
		}
		else if (dwBytesRead && !m_bAbort)
		{
			//Write the data to file
			TRY
			{
				m_FileToWrite.Write(szReadBuf, dwBytesRead);
			}
			CATCH(CFileException, e);                                          
			{
				TRACE(_T("An exception occured while writing to the download file\n"));
				HandleThreadErrorWithLastError(IDS_HTTPDOWNLOAD_ERROR_READFILE, e->m_lOsError);
				e->Delete();
				return;
			}
			END_CATCH
				
			//Increment the total number of bytes read
			dwTotalBytesRead += dwBytesRead;  
			UpdateControlsDuringTransfer(dwTotalBytesRead, dwLastPercentage, bGotFileSize, dwFileSize);
		}
	}
	while (dwBytesRead && !m_bAbort);
	
	//Delete the file being downloaded to if it is present and the download was aborted
	m_FileToWrite.Close();
	if (m_bAbort)
		::DeleteFile(m_sFileToDownloadInto);
	
	//We're finished
	PostMessage(WM_HTTPDOWNLOAD_THREAD_FINISHED);
}

void CDlgDownload::UpdateControlsDuringTransfer(DWORD dwTotalBytesRead, 
		DWORD& dwLastPercentage, BOOL bGotFileSize, DWORD dwFileSize)
{
	if (bGotFileSize)
	{
		//Update the percentage downloaded in the caption
		DWORD dwPercentage = (DWORD) (dwTotalBytesRead * 100.0 / dwFileSize);
		if (dwPercentage != dwLastPercentage)
		{
			//Update the progress control bar
			SetProgress(dwTotalBytesRead);
		}
	}
}

void CDlgDownload::OnDestroy() 
{
	//Wait for the worker thread to exit
	if (m_pThread)
	{
		WaitForSingleObject(m_pThread->m_hThread, INFINITE);
		delete m_pThread;
		m_pThread = NULL;
	}
	
	//Free up the internet handles we may be using
	if (m_hHttpFile)
	{
		::InternetCloseHandle(m_hHttpFile);
		m_hHttpFile = NULL;
	}
	if (m_hHttpConnection)
	{
		::InternetCloseHandle(m_hHttpConnection);
		m_hHttpConnection = NULL;
	}
	if (m_hInternetSession)
	{
		::InternetCloseHandle(m_hInternetSession);
		m_hInternetSession = NULL;
	}
	
	//Let the parent class do its thing
	CDialog::OnDestroy();
}

void CDlgDownload::OnCancel() 
{
	//Just set the abort flag to TRUE and
	//disable the cancel button
	m_bAbort = TRUE;	
	GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
}

void CDlgDownload::OnClose() 
{
	if (m_bSafeToClose)	
		CDialog::OnClose();
	else
	{
		//Just set the abort flag to TRUE and
		//disable the cancel button
		m_bAbort = TRUE;	
		GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产露脸91国语对白| 久久婷婷成人综合色| 欧美日韩国产综合一区二区| 精品91自产拍在线观看一区| 中文字幕亚洲区| 国产一区视频网站| 91精品国产综合久久福利 | 成人午夜在线视频| 欧美一区二区在线观看| 亚洲免费av高清| 国产黄色精品网站| 欧美日本在线看| 亚洲视频一二区| 国产aⅴ精品一区二区三区色成熟| 制服丝袜亚洲精品中文字幕| 亚洲精品五月天| 99re这里只有精品6| 国产午夜精品在线观看| 精品一区精品二区高清| 9191国产精品| 无码av免费一区二区三区试看| 99久久亚洲一区二区三区青草| 久久久国产一区二区三区四区小说 | 亚洲图片欧美一区| 91蜜桃在线观看| 国产精品国产馆在线真实露脸| 国产成人免费视频精品含羞草妖精 | 久国产精品韩国三级视频| 欧美理论在线播放| 天堂蜜桃91精品| 欧美精品久久天天躁| 亚洲一区中文日韩| 欧美视频在线一区二区三区| 一区二区三区波多野结衣在线观看| av在线播放一区二区三区| 国产精品麻豆一区二区| 成人av网址在线| 中文字幕一区二区三区不卡 | 成人高清视频在线观看| 中文字幕五月欧美| 日本电影亚洲天堂一区| 亚洲妇熟xx妇色黄| 欧美一区二区播放| 国产一区二三区好的| 国产网站一区二区| 91在线国内视频| 性久久久久久久久| 精品久久一区二区三区| 国产激情一区二区三区四区| 中文字幕精品一区二区三区精品| 不卡视频一二三四| 亚洲综合小说图片| 日韩你懂的在线播放| 国产精品99久久久久久有的能看| 国产精品乱人伦中文| 欧美综合一区二区| 美洲天堂一区二卡三卡四卡视频| 久久人人爽人人爽| 99久久国产综合精品色伊 | 亚洲欧美另类小说视频| 欧美性猛交xxxxxxxx| 久久99精品视频| 国产精品伦理在线| 制服丝袜中文字幕一区| 国产99久久久国产精品免费看| 亚洲欧美另类图片小说| 欧美一区二区视频观看视频 | 国产精品国产自产拍在线| 欧美三级中文字幕| 国产精品一区二区久久精品爱涩| 亚洲日本乱码在线观看| 欧美草草影院在线视频| 色综合中文字幕国产 | 成人一区二区视频| 亚洲va欧美va天堂v国产综合| 欧美哺乳videos| 91久久线看在观草草青青| 久久99国产精品麻豆| 亚洲乱码国产乱码精品精的特点| 日韩一区二区在线免费观看| 92精品国产成人观看免费| 国产在线麻豆精品观看| 亚洲二区在线视频| 最新国产成人在线观看| 久久亚洲一区二区三区明星换脸| 久久久久亚洲蜜桃| 欧美在线观看一区二区| 不卡一卡二卡三乱码免费网站| 麻豆一区二区99久久久久| 一区二区在线免费观看| 欧美激情中文字幕一区二区| 日韩欧美电影一二三| 欧美三级韩国三级日本一级| 波多野洁衣一区| 国产精品99久久不卡二区| 青草国产精品久久久久久| 一级精品视频在线观看宜春院| 久久久国产精品午夜一区ai换脸| 日韩一区二区三区视频在线观看| 91久久精品网| 91一区一区三区| 成人黄页在线观看| 国产成人综合在线| 狠狠色丁香九九婷婷综合五月| 午夜精品福利一区二区蜜股av| 一区二区视频在线| 自拍偷拍欧美精品| 国产精品久久久久久久第一福利 | 亚洲免费毛片网站| 国产精品毛片a∨一区二区三区| 国产亚洲一区二区三区四区 | 国产一区二区不卡老阿姨| 蜜臀av一区二区在线观看| 亚洲 欧美综合在线网络| 亚洲一区二区三区美女| 亚洲综合一区二区精品导航| 亚洲已满18点击进入久久| 一区二区在线观看免费| 亚洲妇熟xx妇色黄| 日本一不卡视频| 精品在线播放午夜| 国产精品99精品久久免费| 国产福利精品一区| 丁香六月综合激情| 92精品国产成人观看免费| 日本二三区不卡| 正在播放亚洲一区| 久久日韩精品一区二区五区| 久久久www免费人成精品| 国产精品电影一区二区三区| 亚洲免费高清视频在线| 亚洲午夜免费视频| 美女一区二区三区| 国产99久久久精品| 91久久精品国产91性色tv| 91精品国产手机| 久久精品视频在线免费观看| 亚洲视频一区在线| 午夜国产精品影院在线观看| 国产一区二区精品在线观看| 成人黄色综合网站| 欧美绝品在线观看成人午夜影视| 日韩美一区二区三区| 久久精品一区二区三区不卡| 综合久久给合久久狠狠狠97色| 亚洲与欧洲av电影| 九色porny丨国产精品| 91免费视频网| 日韩一区二区三区电影| 亚洲国产精品高清| 日精品一区二区| 大白屁股一区二区视频| 欧美日韩国产综合视频在线观看 | 亚洲一区国产视频| 激情综合色播五月| 91极品美女在线| 久久久久久亚洲综合| 一区二区在线观看视频| 国产尤物一区二区在线| 欧美日韩综合在线| 国产欧美精品一区aⅴ影院 | 亚洲日本电影在线| 精品综合免费视频观看| 色成年激情久久综合| 久久尤物电影视频在线观看| 亚洲国产日韩精品| 不卡av在线免费观看| 欧美一区二区免费| 亚洲国产欧美在线人成| 成人午夜视频在线观看| 欧美成人三级电影在线| 一区二区三区中文字幕| 国产精品一区二区久激情瑜伽| 欧美疯狂做受xxxx富婆| 亚洲狠狠丁香婷婷综合久久久| 国产一区美女在线| 日韩精品中文字幕在线不卡尤物| 一区二区三区四区视频精品免费 | 亚洲精品在线免费播放| 亚洲一区二区视频在线观看| 成人免费黄色在线| 久久久亚洲精品一区二区三区| 亚洲成在人线免费| 在线区一区二视频| 亚洲欧美国产三级| 成人sese在线| 国产日产亚洲精品系列| 国产专区欧美精品| 精品久久久久一区二区国产| 蜜臀av一区二区| 日韩视频国产视频| 亚洲va国产天堂va久久en| 欧美日韩在线直播| 国产精品996| 日本一区二区三区国色天香| 韩国精品主播一区二区在线观看| 日韩午夜电影在线观看| 久久国产乱子精品免费女| 在线播放/欧美激情| 视频一区二区三区在线|