void CDownloadsView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CMainFrame *pMain = (CMainFrame *)AfxGetMainWnd();
	if(pMain->m_myIOCPSocket.m_downloadFileDataList.GetCount() > 0){	// 다운로드중일때만
		// 다운로드되는목록과 실제다운되고있는목록을 비교 (중첩 while)
		// 실제다운되고있는것
		POSITION posIOCP;	
		posIOCP = pMain->m_myIOCPSocket.m_downloadFileDataList.GetHeadPosition();
		MY_FILE_DATA *pIOCP;

		// 다운로드목록데이타
		POSITION posData;	
		posData = pMain->m_downloadFileList.GetHeadPosition();
		MY_DOWNLOAD_FILE_LIST *pData;
		
		BOOL bOut = TRUE;
		while(posIOCP){	
			bOut = TRUE;
			pIOCP = &(pMain->m_myIOCPSocket.m_downloadFileDataList.GetAt(posIOCP));
			while(posData){
				pData = &(pMain->m_downloadFileList.GetAt(posData));
				if(pIOCP->nIndex == pData->nIndex){
					for(int i=0; i<m_listDownloads.GetItemCount(); i++){	// 리스트목록과 번호비교
						char szNum[5];
						m_listDownloads.GetItemText(i, 6, szNum, 5);						
						if(pIOCP->nIndex == (UINT)atoi(szNum)){
							// 받은데이타양		
							char szReceiveSize[256];
							sprintf(szReceiveSize, "%s KB", pMain->ChangeComma(pIOCP->nReceiveSize));
							m_listDownloads.SetItemText(i, 2, szReceiveSize);
							
							float total = (float)pIOCP->nFileSize;
							float recv = (float)pIOCP->nReceiveSize;
							int pu = (int)ceil((recv / total) * 100);
							sprintf(szReceiveSize, "[ %d%% ]", pu);
							m_listDownloads.SetItemText(i, 3, szReceiveSize);
						//	pIOCP->nReceiveSize = pData->nReceiveSize;
							break;
							bOut = FALSE;
						}						
					}
				}
				if(bOut == FALSE){
					break;
				}
				pMain->m_downloadFileList.GetNext(posData);
			}			
			pMain->m_myIOCPSocket.m_downloadFileDataList.GetNext(posIOCP);			
		}
	}
	CFormView::OnTimer(nIDEvent);
}
void CDownloadsView::AddItem(CString fileName, DWORD size, DWORD nReceiveSize, CString strStatus, CString serverName, UINT nNum)
{
	CMainFrame *pMain = ((CMainFrame *)AfxGetMainWnd());

	SHFILEINFO sfi;
    SHGetFileInfo(fileName, 0, &sfi, sizeof(SHFILEINFO), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON );
	int img = sfi.iIcon;

	LV_ITEM a;
	a.iItem = m_listDownloads.GetItemCount();	// 삽입 위치
	a.mask = LVIF_TEXT | LVIF_IMAGE  | LVIF_STATE;	// 실직적으로 표현될값
	a.iSubItem = 0;	// 열인덱스
	a.iImage = img;	// 이미지 인덱스
	a.stateMask = LVIS_STATEIMAGEMASK;	// 상태변화를 Mask 처리
	a.state = INDEXTOSTATEIMAGEMASK(1);	// 유효한 상태 비트
	fileName.Format("%s", fileName);
	a.pszText = (LPSTR)(LPCTSTR) fileName;	// 문자열 
	CString temp;
	m_listDownloads.InsertItem(&a);	
	temp.Format("%s KB", pMain->ChangeComma(size));
	m_listDownloads.SetItemText(a.iItem, 1, temp);
	temp.Format("%s KB", pMain->ChangeComma(nReceiveSize));
	m_listDownloads.SetItemText(a.iItem, 2, temp);

	char szReceiveSize[256];
	float total = (float)size;
	float recv = (float)nReceiveSize;
	int pu = (int)ceil((recv / total) * 100);
	sprintf(szReceiveSize, "[ %d%% ]", pu);		
	m_listDownloads.SetItemText(a.iItem, 3, szReceiveSize);

	m_listDownloads.SetItemText(a.iItem, 4, strStatus);
	m_listDownloads.SetItemText(a.iItem, 5, serverName);
	temp.Format("%d", nNum);
	m_listDownloads.SetItemText(a.iItem, 6, temp);	// 의미는 없지만 조금더 편하게 하기위해번호를 부여(실제다운받는것고연동을위해)
}