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

📄 testdownview.cpp

📁 模拟迅雷的下载工具软件
💻 CPP
字号:
// TestDownView.cpp : implementation of the CTestDownView class
//

#include "stdafx.h"
#include "LeoBlock2004.h"

#include "TestDownDoc.h"
#include "TestDownView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDownView
IMPLEMENT_DYNCREATE(CTestDownView, CView)

BEGIN_MESSAGE_MAP(CTestDownView, CView)
	//{{AFX_MSG_MAP(CTestDownView)
	ON_WM_CREATE()
	ON_COMMAND(ID_DOWN_START, OnDownStart)
	ON_WM_SIZE()
	ON_COMMAND(ID_DOWN_STOP, OnDownStop)
	ON_COMMAND(ID_DOWN_AGAIN, OnDownAgain)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_MESSAGE(WM_LISTINFO,OnListInfo)
	ON_MESSAGE(WM_LEODOWNINFO,OnLeoDownInfo)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestDownView construction/destruction

CTestDownView::CTestDownView()
{
	// TODO: add construction code here
	m_pFrameWnd=NULL;
}

CTestDownView::~CTestDownView()
{
	//delete am_ListNew;
}

BOOL CTestDownView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestDownView drawing

void CTestDownView::OnDraw(CDC* pDC)
{
	CTestDownDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

}

/////////////////////////////////////////////////////////////////////////////
// CTestDownView printing

BOOL CTestDownView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTestDownView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTestDownView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTestDownView diagnostics

#ifdef _DEBUG
void CTestDownView::AssertValid() const
{
	CView::AssertValid();
}

void CTestDownView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CTestDownDoc* CTestDownView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDownDoc)));
	return (CTestDownDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestDownView message handlers


int CTestDownView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	return 0;
}

void CTestDownView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CRect rRect;
	GetClientRect(rRect);
	rRect.left+=1;
	rRect.top+=1;
	rRect.right-=1;
	rRect.bottom-=1;
	
	m_ListNew.CreateNew(this,rRect,IDC_LISTNEW,IDR_SHORTMENU_DOWN,IDB_BITMAP3);
	m_ListNew.SetDefaultTitle();

	//Set Column Width LVSCW_AUTOSIZE
	for(int i=0;i<9;i++)
		m_ListNew.SetColumnWidth(i,70);

	//m_pFrameWnd=AfxGetMainWnd();

	//*************Initial ListCtrl
	LPTSTR lpszText[8];
	for(i=0;i<8;i++)
		lpszText[i]="";

	CString sFile,sLength,sSpeed,sComment,sUrl;

	HKEY nhKeyRoot=HKEY_CURRENT_USER;
	LPSTR nszSubKeyPath="Software\\BLeo2004\\DownLoad\\Down";
	LPSTR nszProgramePath="Software\\BLeo2004\\Dir";
	int nNumber;
	CString sTemp;

	if(v_DownRegistry.Open(nhKeyRoot,nszProgramePath))
	{
		v_DownRegistry.Read("Number",nNumber);
		if(nNumber!=0)
		{
			v_DownRegistry.Close();
			int nImage=0;
			for(int i=1;i<=nNumber;i++)
			{
				sTemp="";
				sTemp.Format("%s%d",nszSubKeyPath,i);
				if(v_DownRegistry.Open(nhKeyRoot,(LPCTSTR)sTemp))
				{

					if(v_DownRegistry.Read("Image",nImage))
					//m_ListNew.SetItemValue(i-1,nImage);

					if(v_DownRegistry.Read("FileName",sFile))
						lpszText[0]=(LPTSTR)(LPCTSTR)sFile;
					//	m_ListNew.SetItemColumnValue(i-1,1,(LPCTSTR)sTemp);

					
					if(v_DownRegistry.Read("FileLength",sLength))
						lpszText[1]=(LPTSTR)(LPCTSTR)sLength;
					else 
						lpszText[1]="";
						//m_ListNew.SetItemColumnValue(i-1,2,(LPCTSTR)sTemp);

					
					if(v_DownRegistry.Read("Percent",sSpeed))
						lpszText[2]=(LPTSTR)(LPCTSTR)sSpeed;
					else
						lpszText[2]="0%";
					//	m_ListNew.SetItemColumnValue(i-1,3,(LPCTSTR)sTemp);
					lpszText[3]="";
					lpszText[4]="";
					lpszText[5]="";
					
					if(v_DownRegistry.Read("Comment",sComment))
						lpszText[6]=(LPTSTR)(LPCTSTR)sComment;
					//	m_ListNew.SetItemColumnValue(i-1,7,(LPCTSTR)sTemp);

					
					if(v_DownRegistry.Read("URL",sUrl))
						lpszText[7]=(LPTSTR)(LPCTSTR)sUrl;
						//m_ListNew.SetItemColumnValue(i-1,8,(LPCTSTR)sTemp);
					
					m_ListNew.SetItemColumnValueB(i-1,8,lpszText,nImage);
					for(int j=0;j<9;j++)
						m_ListNew.SetColumnWidth(j,LVSCW_AUTOSIZE);
					m_ListNew.SetAutoSize(4,3);		

					sFile=sLength=sSpeed=sComment=sUrl="";

				}
			}
		}
	}

	v_DownRegistry.Close();
	



}

void CTestDownView::OnDownStart() 
{
	// TODO: Add your command handler code here
	//WM_DOWNSTARTBREAK
	
	DOWN_STARTBREAK pDownStartBreak;
	
	HKEY nhKeyRoot=HKEY_CURRENT_USER;
	LPSTR nszSubKeyPath="Software\\BLeo2004\\DownLoad\\Down";
	CString sTemp,sTemp0,sTemp1,sTemp2,sTemp3;
	
	sTemp.Format("%s%d",nszSubKeyPath,m_nItem+1);
	if(v_DownRegistry.Open(nhKeyRoot,(LPCTSTR)sTemp))
	{
			pDownStartBreak.nParentNum=m_nItem+1;
			pDownStartBreak.strRegSubPath=sTemp;
			if(v_DownRegistry.Read("Percent",sTemp0))
			{
				if(sTemp0!="100%")
				{
					v_DownRegistry.Read("FileName",sTemp1);
					pDownStartBreak.strFilePath=sTemp1;

					v_DownRegistry.Read("Comment",sTemp2);
					pDownStartBreak.strComment=sTemp2;
					
					v_DownRegistry.Read("URL",sTemp3);
					pDownStartBreak.strLocationUrl=sTemp3;
					pDownStartBreak.nBreakRcv=1;
					CFileFind pFind;
					if(pFind.FindFile((LPCTSTR)sTemp1))
					{
						LV_ITEM lItem;
						lItem.mask=LVIF_IMAGE;
						lItem.iItem=m_nItem;
						lItem.iSubItem=0;
						lItem.iImage=1;

						m_ListNew.SetItem(&lItem);

						::SendMessage(m_pFrameWnd->m_hWnd,WM_DOWNSTARTBREAK,0,(LPARAM)&pDownStartBreak);
					}
					else
						MessageBox("文件名不存在,请重新下载!","Leo",MB_OK|MB_ICONSTOP);

					pFind.Close();

				}
			}
	}
	else
		MessageBox("信息已丢失,不能继续下载!","Leo",MB_OK|MB_ICONSTOP);
	
	v_DownRegistry.Close();
	

}

void CTestDownView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(m_ListNew)
	{
		CRect rRect;
		GetClientRect(rRect);
		rRect.left+=1;
		rRect.top+=1;
		rRect.right-=1;
		rRect.bottom-=1;
	
		m_ListNew.MoveWindow(rRect.left,rRect.top,rRect.right,rRect.bottom);
	}

}

void CTestDownView::OnListInfo(WPARAM wParam,LPARAM lParam)
{
	LIST_INFO *nListInfo=(LIST_INFO*)lParam;
	m_nItem=nListInfo->nItem;
	m_nSubItem=nListInfo->nSubItem;

}

void CTestDownView::OnLeoDownInfo(WPARAM wParam,LPARAM lParam)
{
	m_pFrameWnd=(CWnd*)lParam;

	//Initial List Value

}

void CTestDownView::OnDownStop() 
{
	// TODO: Add your command handler code here


	LV_ITEM lItem;
	lItem.mask=LVIF_IMAGE;
	lItem.iItem=m_nItem;
	lItem.iSubItem=0;
	lItem.iImage=2;
	m_ListNew.SetItem(&lItem);

	//==================
	HKEY nhKeyRoot=HKEY_CURRENT_USER;
	LPSTR nszSubKeyPath="Software\\BLeo2004\\DownLoad\\Down";
	CString sTemp;
	sTemp.Format("%s%d",nszSubKeyPath,m_nItem+1);
	if(v_DownRegistry.Open(nhKeyRoot,(LPCTSTR)sTemp))
	{
		v_DownRegistry.Write("Image",2);
	}
	//==================

	DOWN_STOPBREAK stDownStopBreak;
	stDownStopBreak.nPID=m_nItem+1;
	::SendMessage(m_pFrameWnd->m_hWnd,WM_DOWNSTOPBREAK,0,(LPARAM)&stDownStopBreak);
}


void CTestDownView::OnDownAgain() 
{
	// TODO: Add your command handler code here
	DOWN_STARTBREAK pDownStartBreak;
	
	HKEY nhKeyRoot=HKEY_CURRENT_USER;
	LPSTR nszSubKeyPath="Software\\BLeo2004\\DownLoad\\Down";
	CString sTemp,sTemp0,sTemp1,sTemp2,sTemp3;
	
	sTemp.Format("%s%d",nszSubKeyPath,m_nItem+1);
	if(v_DownRegistry.Open(nhKeyRoot,(LPCTSTR)sTemp))
	{
		pDownStartBreak.nParentNum=m_nItem+1;
		pDownStartBreak.strRegSubPath=sTemp;

		v_DownRegistry.Read("FileName",sTemp1);
		pDownStartBreak.strFilePath=sTemp1;

		
		v_DownRegistry.Read("Comment",sTemp2);
		pDownStartBreak.strComment=sTemp2;

		
		v_DownRegistry.Read("URL",sTemp3);
		pDownStartBreak.strLocationUrl=sTemp3;
		pDownStartBreak.nBreakRcv=0;
		::SendMessage(m_pFrameWnd->m_hWnd,WM_DOWNSTARTBREAK,0,(LPARAM)&pDownStartBreak);
	}
	
}

⌨️ 快捷键说明

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