📄 mainfrm.cpp
字号:
return 0L;
}
UINT CMyAppThread::PreRecieveFileThread(LPVOID lParam)
{
CMyAppThread* pThread=(CMyAppThread*)lParam;
CFtpParaClass:: FILE_FTP_INFO* pInfo=new CFtpParaClass::FILE_FTP_INFO;
WIN32_FIND_DATA fileData;
HINTERNET hFind;
CString szFtpInfo,str,strFtp;
szFtpInfo="创建"+m_szLocDirectory+"目录";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
CreateDirectory(m_szLocDirectory,NULL);
::SetCurrentDirectory(m_szLocDirectory);
if(IsFree)
pLocView->SendMessage(WM_SETDIR,0,(LPARAM)(LPCTSTR)m_szLocDirectory);
FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
szFtpInfo="进入"+m_szFtpDirectory+"目录成功";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
CString tFile;
if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&fileData,0,0)))
goto end;
do
{
tFile=fileData.cFileName;
if(tFile=="."||tFile==".."||fileData.dwFileAttributes==FILE_ATTRIBUTE_HIDDEN)continue;
str=m_szLocDirectory;
strFtp=m_szFtpDirectory;
if(m_szLocDirectory.Right(1)=='\\')
str+=tFile;
else
str+="\\"+tFile;
if(m_szFtpDirectory.Right(1)=='/')
strFtp+=tFile;
else
strFtp+="/"+tFile;
if(fileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
pServView->SendMessage(WM_PRERECEIVEFILE,(WPARAM)(LPCTSTR)str,(LPARAM)(LPCTSTR)strFtp);
else
{
szFtpInfo="正在接收"+tFile;
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
if(!FtpGetFile(hFtpConn,strFtp,str,FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY |
INTERNET_FLAG_NO_CACHE_WRITE,0))
{
szFtpInfo="接收"+strFtp+"出错";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
break;
}
if(IsFree)
{
IsFree=FALSE;
strcpy(pInfo->szFileName,tFile);
strcpy(pInfo->szFileDate,"");
strcpy(pInfo->szFileSize,"");
pInfo->nType=FILEICON;
::PostMessage(pLocView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,SERVFILE);
}
}
}while(InternetFindNextFile(hFind,&fileData));
InternetCloseHandle(hFind);
end:
delete pInfo;
delete pThread;
nThreadCount--;
return 0L;
}
UINT CMyAppThread::PreDeleteFileThread(LPVOID lParam)
{
CMyAppThread* pThread=(CMyAppThread*)lParam;
CFtpParaClass:: FILE_FTP_INFO* pInfo=new CFtpParaClass::FILE_FTP_INFO;
WIN32_FIND_DATA fileData;
HINTERNET hFind;
CString szFtpInfo,strFtp;
FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
szFtpInfo="进入"+m_szFtpDirectory+"目录成功";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
CString tFile;
if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&fileData,0,0)))
goto end;
do
{
tFile=fileData.cFileName;
if(tFile=="."||tFile==".."||fileData.dwFileAttributes==FILE_ATTRIBUTE_HIDDEN)continue;
strFtp=m_szFtpDirectory;
if(m_szFtpDirectory.Right(1)=='/')
strFtp+=tFile;
else
strFtp+="/"+tFile;
if(fileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
pServView->SendMessage(WM_PREDELETEFILE,0,(LPARAM)(LPCTSTR)strFtp);
else
{
szFtpInfo="正在删除"+tFile;
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
if(!FtpDeleteFile(hFtpConn,strFtp))
{
szFtpInfo="删除"+strFtp+"出错";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
break;
}
}
}while(InternetFindNextFile(hFind,&fileData));
InternetCloseHandle(hFind);
end:
FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory+"/"+"..");
szFtpInfo="正在删除"+m_szFtpDirectory+"目录";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
while(1)
{
if(FtpRemoveDirectory(hFtpConn,m_szFtpDirectory))
//必须在此添加修改m_ctServDir的功能;
break;
::Sleep(100);
}
delete pInfo;
delete pThread;
nThreadCount--;
return 0L;
}
UINT CMyAppThread::DeleteFileThread(LPVOID lParam)
{
IsFree=TRUE;
int i=0;
CFtpParaClass:: FILE_FTP_INFO* pInf=new (CFtpParaClass::FILE_FTP_INFO);
CFtpParaClass::SEND_RECEIVE_INFO* pInf1=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
CMyAppThread* pThread=(CMyAppThread*)pInf1->pThread;
CFtpParaClass::FILE_COUNT_INFO* pInfo=pInf1->pCount;
CString strFtp,szFtpInfo,DirName;
if(!hFtpConn)
goto end;
FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
::SetCurrentDirectory(m_szLocDirectory);
for(;i<m_nCount;i++)
{
strFtp=m_szFtpDirectory;
DirName=pInfo[i].fileName;
if(DirName=="..")continue;
if(m_szFtpDirectory.Right(1)=='/')
strFtp+=DirName;
else
strFtp+="/"+DirName;
if(pInfo[i].ufileFlag==FILEICON)
{
szFtpInfo="删除"+DirName;
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
if(FtpDeleteFile(hFtpConn,strFtp))
{
continue;
}
else
{
szFtpInfo="删除"+DirName+"出错";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
break;
}
}
else;
pServView->SendMessage(WM_PREDELETEFILE,0,(LPARAM)(LPCTSTR)strFtp);
}
end:
nThreadCount--;
::Sleep(10);
while(1)
{
if(nThreadCount==0)
{
szFtpInfo="文件删除结束,退回"+m_szLocDirectory;
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
::SendMessage(pServView->m_hWnd,WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
break;
}
::Sleep(100);
}
delete[] pInfo;
delete pInf;
delete pThread;
delete pInf1;
return 0L;
}
UINT CMyAppThread::RenameFileThread(LPVOID lParam)
{
CString szFtpInfo;
CFtpParaClass::FILE_CHANGE_INFO* pInfo=(CFtpParaClass::FILE_CHANGE_INFO*)lParam;
CMyAppThread* pThread=(CMyAppThread*)pInfo->pThread;
szFtpInfo="正在连接"+m_szFtpName+"服务器";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
if(!hFtpConn)
{
szFtpInfo="未连上"+m_szFtpName+"服务器,请查明原因,目前只能返回";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
::Sleep(10);
goto end;
}
szFtpInfo=m_szFtpName+"服务器连接成功,现进行改名操作";
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
szFtpInfo="正在把";
szFtpInfo+=pInfo->OldName;
szFtpInfo+="改为";
szFtpInfo+=pInfo->NewName;
pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
if(FtpRenameFile(hFtpConn,pInfo->OldName,pInfo->NewName))
szFtpInfo="改名成功";
else
{
szFtpInfo="改名失败,有可能有重名文件";
pServView->PostMessage(WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
}
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
end:
::Sleep(0);
delete pThread;
delete pInfo;
return 0L;
}
void CLocFileView::OnDblclkLocFile(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
CString str,buf;
int iIcon,iIconSel;
str.Format("%d",pLocInfo->item);
if(str=="-1")return;
int nItem=atoi(str);
DWORD dwFlag=m_ctLocFile.GetItemData(nItem);
if(dwFlag==FILEICON)
{
OnLocFileOpen();
return;
}
buf=m_ctLocFile.GetItemText(nItem,0);
nItem=m_ctLocDir.GetCurSel();
m_ctLocDir.GetLBText(nItem,str);
if(str.Right(1)!="\\")
str+="\\";
str+=buf;
GetFileIcon(str,&iIcon,&iIconSel);
int i=m_ctLocDir.FindStringExact(-1,str);
if(i==CB_ERR)
{
int iCount=m_ctLocDir.GetCount();
if(iCount==m_iDirCount)
{
i=InsertLocDir(str,iIcon,iIconSel);
}
else
{
m_ctLocDir.DeleteItem(m_iDirCount);
i=InsertLocDir(str,iIcon,iIconSel);
}
}
m_ctLocDir.SetCurSel(i);
CMyAppThread* pThread=new CMyAppThread(str);
BeginFindLocFile(pThread);
*pResult = 0;
}
void CLocFileView::OnSize(UINT nType, int cx, int cy)
{
// CFormView::OnSize(nType, cx, cy);
if(m_ctLocDir.m_hWnd)
m_ctLocDir.SetWindowPos(this,0,0,cx-3,0,SWP_NOZORDER|SWP_NOMOVE);
if(m_ctLocFile.m_hWnd)
{
m_ctLocFile.ShowWindow(SW_HIDE);
m_ctLocFile.SetWindowPos(this,0,0,cx-1,cy-22,SWP_NOZORDER|SWP_NOMOVE);
m_ctLocFile.ShowWindow(SW_SHOW);
}
}
void CServFileView::OnSize(UINT nType, int cx, int cy)
{
// CFormView::OnSize(nType, cx, cy);
if(m_ctServDir.m_hWnd&&m_ctBack.m_hWnd)
{
m_ctServDir.SetWindowPos(this,0,0,cx-30,0,SWP_NOZORDER|SWP_NOMOVE);
m_ctBack.SetWindowPos(this,cx-28,0,0,0,SWP_NOZORDER|SWP_NOSIZE);
}
if(m_ctServFile.m_hWnd)
{
m_ctServFile.ShowWindow(SW_HIDE);
m_ctServFile.SetWindowPos(this,0,0,cx,cy-22,SWP_NOZORDER|SWP_NOMOVE);
m_ctServFile.ShowWindow(SW_SHOW);
}
}
BOOL CServFileView::SetServImageList(UINT nBitmapID)
{
if(m_ctServImageList.Create(nBitmapID,16,1,RGB(0,255,0)))
{
m_ctServFile.SetImageList(&m_ctServImageList,LVSIL_SMALL);
m_ctServDir.SetImageList(&m_ctServImageList);
}
else
return FALSE;
return TRUE;
}
void CLocFileView::OnSelchangeLocDir()
{
CString str;
char lpBuffer[MAX_PATH];
::GetCurrentDirectory(MAX_PATH,lpBuffer);
int i=m_ctLocDir.GetCurSel();
m_ctLocDir.GetLBText(i,str);
if(str==lpBuffer)return;
i=0;
while(1)
{
if(!SetCurrentDirectory(str))
{
i++;
if(i<2)
{
AfxMessageBox("请插入磁盘再试");
continue;
}
str=lpBuffer;
if((i=m_ctLocDir.FindStringExact(-1,str))!=-1)
m_ctLocDir.SetCurSel(i);
}
else
{
CMyAppThread* pThread=new CMyAppThread(str);
BeginFindLocFile(pThread);
}
break;
}
}
void CServFileView::OnDblclkServFile(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
CString str,buf;
str.Format("%d",pLocInfo->item);
if(str=="-1")
return;
int nItem=atoi(str);
buf=m_ctServFile.GetItemText(nItem,0);
DWORD dwFlag=m_ctServFile.GetItemData(nItem);
if(dwFlag==FILEICON)
return;
nItem=m_ctServDir.GetCurSel();
m_ctServDir.GetLBText(nItem,str);
if(str!="/")
str+="/";
str+=buf;
nItem=m_ctServDir.FindStringExact(-1,str);
if(nItem==CB_ERR)
nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
m_ctServDir.SetCurSel(nItem);
OnQuickConnect();
if(buf=="..")
m_ctServDir.DeleteItem(nItem);
*pResult = 0;
}
void CLocFileView::OnBegindragLocFile(NMHDR* pNMHDR, LRESULT* pResult)
{
if(m_bDragging)return;
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
int nItem=pNMListView->iItem;
POINT pt=pNMListView->ptAction;
m_pDragImageList=m_ctLocFile.CreateDragImage(nItem,&pt);
m_bDragging=TRUE;
m_pDragImageList->BeginDrag(0,CPoint(0,0));
m_pDragImageList->DragEnter(NULL,pt);
SetCapture();
SetCursor(m_hDragCursor);
*pResult = 0;
}
void CLocFileView::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_bDragging)
{
CRect rect;
pServView->m_ctServFile.GetWindowRect(&rect);
ClientToScreen(&point);
if(rect.PtInRect(point)&&m_bConnected)
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
else
SetCursor(m_hDragCursor);
m_pDragImageList->DragMove(point);
}
CFormView::OnMouseMove(nFlags, point);
}
void CLocFileView::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_bDragging)
{
m_bDragging=FALSE;
CImageList::DragLeave(NULL);
CImageList::EndDrag();
ReleaseCapture();
delete m_pDragImageList;
m_pDragImageList=NULL;
CRect rect;
pServView->m_ctServFile.GetWindowRect(&rect);
ClientToScreen(&point);
if(rect.PtInRect(point)&&m_bConnected)
OnLocFileSend();
}
CFormView::OnLButtonUp(nFlags, point);
}
void CLocFileView::OnLocFileSend()
{
if(!m_bConnected)return;
CString str,strFtp;
int i=0;
POSITION iPos;
int nItem=pServView->m_ctServDir.GetCurSel();
pServView->m_ctServDir.GetLBText(nItem,strFtp);
nItem=m_ctLocDir.GetCurSel();
m_ctLocDir.GetLBText(nItem,str);
i=m_ctLocFile.GetSelectedCount();
FILE_COUNT_INFO* pFileCount=new FILE_COUNT_INFO[i];
SEND_RECEIVE_INFO* pSeRe=new SEND_RECEIVE_INFO;
iPos=m_ctLocFile.GetFirstSelectedItemPosition();
for(int j=0;j<i;j++)
{
int nItem=m_ctLocFile.GetNextSelectedItem(iPos);
m_ctLocFile.GetItemText(nItem,0,pFileCount[j].fileName,256);
pFileCount[j].ufileFlag=m_ctLocFile.GetItemData(nItem);
}
CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE,i);
pSeRe->pCount=pFileCount;
pSeRe->pThread=pThread;
if(!BeginSendFile(pSeRe))
AfxMessageBox("建立文件发送线程出错");
}
void CLocFileView::OnLocFileOpen()
{
CString str,szFile;
int nItem,i;
nItem=m_ctLocDir.GetCurSel();
if(nItem==CB_ERR)return;
m_ctLocDir.GetLBText(nItem,str);
szFile=str;
POSITION iPos=m_ctLocFile.GetFirstSelectedItemPosition();
nItem=m_ctLocFile.GetNextSelectedItem(iPos);
i=m_ctLocFile.GetItemData(nItem);
if(str.Right(1)=="\\")
szFile+=m_ctLocFile.GetItemText(nItem,0);
else
szFile+="\\"+m_ctLocFile.GetItemText(nItem,0);
if(i==FILEICON)
::ShellExecute(m_hWnd,NULL,szFile,"open",str,SW_SHOWDEFAULT);
else
{
CMyAppThread* pThread=new CMyAppThread(szFile);
BeginFindLocFile(pThread);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -