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

📄 downloadfilelist.cpp

📁 BQYAHOO的Visual C++源代码
💻 CPP
字号:
//负责处理右上方列表控件


#include "stdafx.h"
#include "resource.h"
#include "downloadfilelist.h"
#include "bqyahoo.h"

extern CXMLDATA XmlData;
extern BQYAHOO * by;
CXMLDESCRIBDATA XmlDescribeData;



//
static bool NowDownAllFile=false;
static bool IsDownLoadOK=false;
//

static string XFileSaveName;
static string XDownLoadUrl;
static HWND XhwndEdit;
static HWND XhwndMain;
DWORD WINAPI DownLoadOneFileThread( LPVOID index )  ;
//
DWORD WINAPI DownLoadAllFileThread( LPVOID index )  ;
//

void CDownLoadFileListCtrl::Init()
{	
	SetExtendedListViewStyle ( LVS_EX_FULLROWSELECT );
	InsertColumn ( 0, "", LVCFMT_LEFT, 0, 0 );
	SetColumnWidth ( 0, LVSCW_AUTOSIZE_USEHEADER );		
			
}



bool CDownLoadFileListCtrl::ShowFile()
{
	DeleteAllItems();
	int len = by->xdata .VFileName .size ();
	if(len==0) return false;
	XmlDescribeData.clear ();
	if(!XmlDescribeData.ReadData ()) return false;
	if(XmlDescribeData.VFileName .size ()!=len) return false;


	by->xdata .GetXMLDescribeData (XmlDescribeData);
			
	for(int n=0;n<len;n++)
	{
		
		InsertItem(n,by->xdata .Vdescribe [n].c_str());
	}
	::SetWindowText (hwndEdit,XmlDescribeData.DescrbeForUser.c_str ());



	return true;
}


LRESULT CDownLoadFileListCtrl::OnLogInOK(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{

	if(!ShowFile()) return 0;

	return 0;
}


LRESULT CDownLoadFileListCtrl::OnLButtonDBClick( UINT , CPoint )
{

	if(!DownLoadOneFile()) return false;
	
	return 0;
}


bool CDownLoadFileListCtrl::DownLoadOneFile()
{
	if(NowDownAllFile) 
	{
		::SetWindowText (hwndEdit,"目前正在下载所有文件");
		return false;
	}
	XhwndEdit=hwndEdit;
	XhwndMain=hwndMain;
	int index = GetSelectedIndex();
	if(index==-1) return false;
	if(index>int(by->xdata .VFileName .size ())) return false;
	
	
	XFileSaveName=by->xdata .VSaveName [index];
	XDownLoadUrl=by->xdata .VFileDownLoadUrl [index];


	
	

	XhwndEdit=hwndEdit;

	DWORD dwThreadId, dwThrdParam = index; 
    HANDLE hThread; 
    hThread = CreateThread( 
        NULL,                        // no security attributes 
        0,                           // use default stack size  
        DownLoadOneFileThread,                  // thread function 
        &dwThrdParam,                // argument to thread function 
        0,                           // use default creation flags 
        &dwThreadId);                // returns the thread identifier 

	if (hThread == NULL) return false;
	CloseHandle( hThread );

	

	
	
	return true;
}



DWORD WINAPI DownLoadOneFileThread( LPVOID index )  
{
	//
	IsDownLoadOK=false;
	//
	string XX;
	XX=XX+"文件 ";
	XX=XX+XFileSaveName;
	//
	::SetWindowText (XhwndEdit,(XX+" 开始下载").c_str());
	if(!by->DownLoadOneFile (XFileSaveName,XDownLoadUrl)) return false;
	::SetWindowText (XhwndEdit,(XX+" 下载结束").c_str());
	char TellSpeed[100];
	::Sleep (1000);
	sprintf(TellSpeed,"目前BQYAHOO的下载速度大约为%dkb/s",by->Speed  );
	::SetWindowText (XhwndEdit,TellSpeed);
	IsDownLoadOK=true;
	return 0;
}



bool CDownLoadFileListCtrl::DownLoadAllFile()
{
	XhwndEdit=hwndEdit;

	DWORD dwThreadId, dwThrdParam =0; 
    HANDLE hThread; 
    hThread = CreateThread( 
        NULL,                        // no security attributes 
        0,                           // use default stack size  
        DownLoadAllFileThread,                  // thread function 
        &dwThrdParam,                // argument to thread function 
        0,                           // use default creation flags 
        &dwThreadId);                // returns the thread identifier 

	if (hThread == NULL) return false;
	CloseHandle( hThread );


	return true;
}


DWORD WINAPI DownLoadAllFileThread( LPVOID index )  
{
	int len=by->xdata .VFileName .size ();
	if(len<=0)return false;

	NowDownAllFile=true;
	for(int n=0;n<len;n++)
	{
		XFileSaveName=by->xdata .VSaveName [n];
		XDownLoadUrl=by->xdata .VFileDownLoadUrl [n];


		

		DWORD dwThreadId, dwThrdParam = 0; 
		HANDLE hThread; 
		hThread = CreateThread( 
        NULL,                        // no security attributes 
        0,                           // use default stack size  
        DownLoadOneFileThread,                  // thread function 
        &dwThrdParam,                // argument to thread function 
        0,                           // use default creation flags 
        &dwThreadId);                // returns the thread identifier 

		if (hThread == NULL) return false;
		CloseHandle( hThread );

		::Sleep (2000);
	
		while(!IsDownLoadOK)
		{
			::Sleep (1000);
		}
		


	}

	NowDownAllFile=false;

	return 0;
}

LRESULT CDownLoadFileListCtrl::OnContextMenu(HWND hwnd, CPoint pt)
{
	
	int index = GetSelectedIndex();
	if(index==-1) return false;	


	HMENU hmenu;            // top-level menu 
    HMENU hmenuTrackPopup;  // shortcut menu 

	hmenu=::GetMenu (this->hwndMain );
	hmenuTrackPopup=::GetSubMenu (hmenu,1);
	 TrackPopupMenu(hmenuTrackPopup, 
            TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
			pt.x, pt.y, 0,this->hwndMain, NULL);

	return true;
}

⌨️ 快捷键说明

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