📄 mainfrm.cpp
字号:
}
void CLocFileView::OnLocFileDelete()
{
POSITION iPos=m_ctLocFile.GetFirstSelectedItemPosition();
if(!iPos)return;
SHFILEOPSTRUCT lpsh;
CString str;
int nItem;
int i=m_ctLocFile.GetSelectedCount();
ZeroMemory(&lpsh,sizeof(lpsh));
lpsh.hwnd= HWND_DESKTOP;
lpsh.fFlags=FOF_NOCONFIRMATION;
lpsh.wFunc=FO_DELETE;
for(int j=0;j<i;j++)
{
nItem=m_ctLocFile.GetNextSelectedItem(iPos);
str=m_ctLocFile.GetItemText(nItem,0);
char buf[MAX_PATH];
strcpy(buf,str);
buf[str.GetLength()+1]='\0';
lpsh.pFrom=buf;
if( 0 != SHFileOperation(&lpsh))
{
AfxMessageBox("删除文件出错,请检查");
return ;
}
}
nItem=m_ctLocDir.GetCurSel();
if(nItem==CB_ERR)
str="C:\\";
else
m_ctLocDir.GetLBText(nItem,str);
CMyAppThread* pThread=new CMyAppThread(str);
BeginFindLocFile(pThread);
}
void CLocFileView::OnLocFileReName()
{
OnFileName(&m_ctLocFile);
}
void CLocFileView::OnRclickLocFile(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
int nItem=pNMListView->iItem;
if(nItem==-1)return;
SetPopMenu(0);
*pResult = 0;
}
void CLocFileView::OnBeginlabeleditLocFile(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CLocFileView::OnEndlabeleditLocFile(NMHDR* pNMHDR, LRESULT* pResult)
{
int nItem;
CString str,buf;
nItem=m_ctLocDir.GetCurSel();
m_ctLocDir.GetLBText(nItem,str);
::SetCurrentDirectory(str);
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM * pItem=&pDispInfo->item;
nItem=pItem->iItem;
buf=m_ctLocFile.GetItemText(nItem,0);
if(pItem->pszText&&buf!=pItem->iItem)
{
m_ctLocFile.SetItemText(pItem->iItem,pItem->iSubItem,pItem->pszText);
::rename(buf,pItem->pszText);
CMyAppThread* pThread=new CMyAppThread(str);
BeginFindLocFile(pThread);
}
*pResult = 0;
}
LRESULT CLocFileView::OnSetLocDir(WPARAM wParam,LPARAM lParam)
{
OnSetLocDirectoryDisplay(wParam,lParam);
m_ctLocFile.SetRedraw(FALSE);
m_ctLocFile.DeleteAllItems();
m_ctLocFile.SetRedraw();
return 0L;
}
/////////////////////////////////////////////////////////////////////////////
// CInputEdit
CInputEdit::CInputEdit(int iItem,int iSubItem,CString& szInitText,CListCtrl* pListCtrl)
{
m_pListCtrl=pListCtrl;
m_iItem=iItem;
m_iSubItem=iSubItem;
m_szInitText=szInitText;
m_bEsc=FALSE;
}
CInputEdit::~CInputEdit()
{
}
BEGIN_MESSAGE_MAP(CInputEdit, CEdit)
//{{AFX_MSG_MAP(CInputEdit)
ON_WM_CHAR()
ON_WM_KILLFOCUS()
ON_WM_CREATE()
ON_WM_NCDESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInputEdit message handlers
void CInputEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar==VK_ESCAPE||nChar==VK_RETURN)
{
if(nChar==VK_ESCAPE)
m_bEsc=TRUE;
GetParent()->SetFocus();
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
CString str;
GetWindowText(str);
CWindowDC dc(this);
CFont* pFont=GetParent()->GetFont();
CFont* pFontDC=dc.SelectObject(pFont);
CSize size=dc.GetTextExtent(str);
dc.SelectObject(pFontDC);
size.cx+=5;
CRect rect,parentrect;
GetClientRect(&rect);
GetParent()->GetClientRect(&parentrect);
ClientToScreen(&rect);
GetParent()->ScreenToClient(&rect);
if(size.cx>rect.Width())
{
if(size.cx+rect.left<parentrect.right)
rect.right=rect.left+size.cx;
else
rect.right=parentrect.right;
MoveWindow(&rect);
}
}
void CInputEdit::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
CString str;
GetWindowText(str);
LV_DISPINFO dispinfo;
dispinfo.hdr.hwndFrom=m_pListCtrl->m_hWnd;
dispinfo.hdr.idFrom=GetDlgCtrlID();
dispinfo.hdr.code=LVN_ENDLABELEDIT;
dispinfo.item.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
dispinfo.item.iItem=m_iItem;
dispinfo.item.iSubItem=m_iSubItem;
dispinfo.item.pszText=m_bEsc?NULL:(LPTSTR)(LPCTSTR)str;
dispinfo.item.cchTextMax=str.GetLength();
GetParent()->SendMessage(WM_NOTIFY,GetParent()->GetDlgCtrlID(),(LPARAM)&dispinfo);
DestroyWindow();
}
BOOL CInputEdit::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_DELETE||pMsg->wParam==VK_ESCAPE||
GetKeyState(VK_CONTROL))
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE;
}
return CEdit::PreTranslateMessage(pMsg);
}
int CInputEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
CFont* font=GetParent()->GetFont();
SetFont(font);
SetWindowText(m_szInitText);
SetFocus();
SetSel(0,-1);
return 0;
}
void CInputEdit::OnNcDestroy()
{
CEdit::OnNcDestroy();
delete this;
}
BOOL CLocFileView::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_ESCAPE&&m_bDragging)
{
m_bDragging=FALSE;
CImageList::DragLeave(NULL);
CImageList::EndDrag();
ReleaseCapture();
delete m_pDragImageList;
return TRUE;
}
return CFormView::PreTranslateMessage(pMsg);
}
void CServFileView::OnBegindragServFile(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_ctServFile.CreateDragImage(nItem,&pt);
m_bDragging=TRUE;
m_pDragImageList->BeginDrag(0,CPoint(0,0));
m_pDragImageList->DragEnter(NULL,pt);
SetCapture();
}
void CServFileView::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_bDragging)
{
CRect rect;
pLocView->m_ctLocFile.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);
}
BOOL CServFileView::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_ESCAPE&&m_bDragging)
{
m_bDragging=FALSE;
CImageList::DragLeave(NULL);
CImageList::EndDrag();
ReleaseCapture();
delete m_pDragImageList;
return TRUE;
}
return CFormView::PreTranslateMessage(pMsg);
}
void CServFileView::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;
pLocView->m_ctLocFile.GetWindowRect(&rect);
ClientToScreen(&point);
if(rect.PtInRect(point)&&m_bConnected)
OnServFileDownload();
}
CFormView::OnLButtonUp(nFlags, point);
}
BOOL CServFileView::BeginReceiveFile(LPVOID pInfo)
{
SEND_RECEIVE_INFO* pInf=(SEND_RECEIVE_INFO*)pInfo;
CMyAppThread* pThread=(CMyAppThread*)pInf->pThread;
if(m_pReceiveFileThread)
{
::WaitForSingleObject(m_pReceiveFileThread->m_hThread,INFINITE);
delete m_pReceiveFileThread;
m_pReceiveFileThread=NULL;
}
if(m_pReceiveFileThread=AfxBeginThread(pThread->StartReceiveFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
0,CREATE_SUSPENDED,NULL))
{
m_pReceiveFileThread->m_bAutoDelete=FALSE;
nThreadCount++;
m_pReceiveFileThread->ResumeThread();
return TRUE;
}
return FALSE;
}
BOOL CServFileView::BeginPreReceiveFile(LPVOID pInfo)
{
CMyAppThread* pThread=(CMyAppThread*)pInfo;
CWinThread* pPreReceiveFile=NULL;
if(pPreReceiveFile=AfxBeginThread(pThread->StartPreReceiveFileThread,pInfo,THREAD_PRIORITY_NORMAL,
0,CREATE_SUSPENDED,NULL))
{
nThreadCount++;
pPreReceiveFile->ResumeThread();
return TRUE;
}
return FALSE;
}
BOOL CServFileView::BeginPreDeleteFile(LPVOID pInfo)
{
CMyAppThread* pThread=(CMyAppThread*)pInfo;
CWinThread* pPreDeleteFile=NULL;
if(pPreDeleteFile=AfxBeginThread(pThread->StartPreDeleteFileThread,pInfo,THREAD_PRIORITY_NORMAL,
0,CREATE_SUSPENDED,NULL))
{
nThreadCount++;
pPreDeleteFile->ResumeThread();
return TRUE;
}
return FALSE;
}
LRESULT CServFileView::OnPreReceiveFile(WPARAM wParam,LPARAM lParam)
{
CString str=(LPCTSTR)wParam;
CString strFtp=(LPCTSTR)lParam;
CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
if(!BeginPreReceiveFile(pThread))
AfxMessageBox("起动发送子线程失败");
return 0L;
}
LRESULT CServFileView::OnPreDeleteFile(WPARAM wParam,LPARAM lParam)
{
CString strFtp=(LPCTSTR)lParam;
CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
if(!BeginPreDeleteFile(pThread))
AfxMessageBox("起动发送子线程失败");
return 0L;
}
void CServFileView::OnRclickServFile(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
int nItem=pNMListView->iItem;
if(nItem==-1||!m_bConnected)return;
SetPopMenu(1);
}
void CServFileView::OnBeginlabeleditServFile(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
*pResult = 0;
}
void CServFileView::OnEndlabeleditServFile(NMHDR* pNMHDR, LRESULT* pResult)
{
int nItem;
CString str,strFtp;
nItem=m_ctServDir.GetCurSel();
if(nItem==CB_ERR)return;
m_ctServDir.GetLBText(nItem,strFtp);
LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
LV_ITEM * pItem=&pDispInfo->item;
nItem=pItem->iItem;
FILE_CHANGE_INFO* pInfo=new FILE_CHANGE_INFO;
str=m_ctServFile.GetItemText(nItem,0);
if(pItem->pszText&&str!=pItem->pszText)
{
CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
pInfo->pThread=pThread;
strcpy(pInfo->OldName,str);
strcpy(pInfo->NewName,pItem->pszText);
if(!BeginRenameFile(pInfo))
AfxMessageBox("建立文件重命名线程出错,返回");
m_ctServFile.SetItemText(pItem->iItem,pItem->iSubItem,pItem->pszText);
}
*pResult = 0;
}
void CServFileView::OnBack()
{
CString str;
int nItem=m_ctServDir.GetCurSel();
if(nItem==CB_ERR)return;
m_ctServDir.GetLBText(nItem,str);
if(str=="/")return;
if(str.Right(1)!="/")
str+="/";
str+="..";
nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
m_ctServDir.SetCurSel(nItem);
OnQuickConnect();
m_ctServDir.DeleteItem(nItem);
}
void CServFileView::OnQuickConnect()
{
CString str;
int nItem=m_ctServDir.GetCurSel();
if(nItem!=CB_ERR)
m_ctServDir.GetLBText(nItem,str);
else
str=" ";
CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),str,TRUE);
if(!BeginFindServFile(pThread))
AfxMessageBox("建立网络线程失败");
}
int CFtpInfoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEditView::OnCreate(lpCreateStruct) == -1)
return -1;
pFtpInfoView=this;
m_NewFont.CreatePointFont(70,"Arial",NULL);
GetEditCtrl().SetFont(&m_NewFont,true);
return 0;
}
void CFtpInfoView::OnChange()
{
return;
}
void CFtpInfoView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// CEditView::OnChar(nChar, nRepCnt, nFlags);
}
void CMainFrame::OnFileDisconnect()
{
CString str,szFtpInfo;
m_wndMyDialogBar.GetDlgItem(IDC_FTPNAME)->GetWindowText(str);
szFtpInfo="已中断与"+str+"的连接";
pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
InternetCloseHandle(hInetSession);
m_wndMyDialogBar.GetDlgItem(IDC_QUICKCONNECT)->ShowWindow(SW_HIDE);
m_bConnected=FALSE;
}
void CMainFrame::OnUpdateFileDisconnect(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bConnected);
}
void CMainFrame::OnFileReconnect()
{
OnQuickconnect();
}
void CMainFrame::OnFileConnect()
{
CString szFtp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -