// myFtpClientView.cpp : implementation of the CMyFtpClientView class // #include "stdafx.h" #include "myFtpClient.h" #include "myFtpClientDoc.h" #include "myFtpClientView.h" #include "messageShowView.h" #include "localDirView.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif int n = 0; CString m_ftpinfo; #define DRAG_DELAY 60 ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView IMPLEMENT_DYNCREATE(CMyFtpClientView, CListView) BEGIN_MESSAGE_MAP(CMyFtpClientView, CListView) //{{AFX_MSG_MAP(CMyFtpClientView) ON_WM_LBUTTONDBLCLK() ON_NOTIFY_REFLECT(HDN_BEGINDRAG, OnBegindrag) ON_WM_MOUSEMOVE() ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnBegindrag) ON_WM_LBUTTONUP() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CListView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView construction/destruction CMyFtpClientView::CMyFtpClientView() { // TODO: add construction code here m_bConnect =false; m_curPath = "//"; m_pFtpConnection = NULL; m_pImageList = NULL; m_isDragging = false; m_pInetSession=new CInternetSession (AfxGetAppName(), 1, PRE_CONFIG_INTERNET_ACCESS); } CMyFtpClientView::~CMyFtpClientView() { } BOOL CMyFtpClientView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CListView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView drawing void CMyFtpClientView::OnDraw(CDC* pDC) { CMyFtpClientDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } void CMyFtpClientView::OnInitialUpdate() { CListView::OnInitialUpdate(); CListCtrl &filelist=GetListCtrl(); CRect rt; filelist.GetWindowRect(&rt); CMyFtpClientDoc* pDoc = GetDocument(); // TODO: You may populate your ListView with items by directly accessing // its list control through a call to GetListCtrl(). SHFILEINFO sfi;//存放文件信息的结构 sys_large_icon = (HIMAGELIST)SHGetFileInfo(NULL,0,&sfi,sizeof(sfi), SHGFI_SYSICONINDEX|SHGFI_LARGEICON);//获得系统图像列表 m_IconList.Attach (sys_large_icon); filelist.SetImageList(&m_IconList,LVSIL_NORMAL); //m_IconList.Detach (); } ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView printing BOOL CMyFtpClientView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMyFtpClientView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMyFtpClientView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView diagnostics #ifdef _DEBUG void CMyFtpClientView::AssertValid() const { CListView::AssertValid(); } void CMyFtpClientView::Dump(CDumpContext& dc) const { CListView::Dump(dc); } CMyFtpClientDoc* CMyFtpClientView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyFtpClientDoc))); return (CMyFtpClientDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMyFtpClientView message handlers void CMyFtpClientView::FileList() { find(); } void CMyFtpClientView::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CListCtrl &filelist=GetListCtrl(); POSITION pos = filelist.GetFirstSelectedItemPosition (); int nItem=filelist.GetNextSelectedItem (pos); CString listname; listname=filelist.GetItemText (nItem,0);//得到双击项的文件名称 if (!(listname.Find(".") > 0)) { m_curPath += listname; m_curPath += "//"; } else { return; } find(); CListView::OnLButtonDblClk(nFlags, point); } void CMyFtpClientView::callConnect() { CMainFrame* mFrm = (CMainFrame*)AfxGetMainWnd(); messageShowView *pEView = (messageShowView *)(mFrm->m_splitterWnd1.GetPane(0,0)); CString msg,str; mFrm->m_wndMyDialogBar.GetDlgItem(IDC_HOST)->GetWindowText(m_host); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_ID)->GetWindowText(m_id); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_KEY)->GetWindowText(m_key); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_PORT)->GetWindowText(m_port); if(!m_bConnect) { msg.Format("正在连接到服务器。。。"); pEView->setMessage(msg); try { m_pFtpConnection=m_pInetSession->GetFtpConnection(_T(m_host),m_id,m_key); } catch(CInternetException *pEx) { TCHAR szError[1024]; if(pEx->GetErrorMessage(szError,1024)) { msg.Format("%s!",szError); pEView->setMessage(msg); AfxMessageBox(szError); return; } else { msg.Format("There was an exception."); pEView->setMessage(msg); AfxMessageBox("There was an exception."); return; } pEx->Delete(); m_pFtpConnection=NULL; } mFrm->m_wndMyDialogBar.GetDlgItem(IDC_HOST)->EnableWindow(false); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_ID)->EnableWindow(false); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_KEY)->EnableWindow(false); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_CONNECT)->SetWindowText("断开连接"); find(); m_bConnect = true; msg += "\r\n" ; msg += "已连接到服务器:" ; msg += m_host; pEView->setMessage(msg); // PutFile(&m_nFileStatus); } else { msg.Format("已断开连接。"); pEView->setMessage(msg); if(m_pFtpConnection!=NULL) { m_pFtpConnection->Close(); delete m_pFtpConnection; m_pFtpConnection = NULL; } GetListCtrl().DeleteAllItems(); m_curPath = "//"; mFrm->m_wndMyDialogBar.GetDlgItem(IDC_HOST)->EnableWindow(true); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_ID)->EnableWindow(true); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_KEY)->EnableWindow(true); mFrm->m_wndMyDialogBar.GetDlgItem(IDC_CONNECT)->SetWindowText("连接"); m_bConnect = false; } } void CMyFtpClientView::callFileBack() { int len = m_curPath.GetLength(); m_curPath = m_curPath.Left(len - 2); int i = m_curPath.ReverseFind('//'); m_curPath = m_curPath.Left( i+1 ); find(); } void CMyFtpClientView::find() { if(m_pFtpConnection == NULL) { return; } CListCtrl &filelist=GetListCtrl(); filelist.DeleteAllItems(); CString m_i; CString m_ii; //用来保存一些临时信息 CStringArray m_Dir; //用数组来保存目录 SHFILEINFO flargeicon; CFtpFileFind finder(m_pFtpConnection); BOOL bWorking=finder.FindFile(_T(m_curPath + "*")); int col = 0; while (bWorking) { bWorking = finder.FindNextFile(); if ( finder.IsDots() ) { continue; } if (finder.IsDirectory()) { m_Dir.Add( finder.GetFileName()); SHGetFileInfo(finder.GetFileName(), NULL, &flargeicon, sizeof(flargeicon), SHGFI_DISPLAYNAME | SHGFI_ICON|SHGFI_LARGEICON); filelist.InsertItem(col,(LPCTSTR)finder.GetFileName(),4); col++; } else { m_i=finder.GetFileName()+"\r\n"; SHGetFileInfo(finder.GetFileName(), NULL, &flargeicon, sizeof(flargeicon), SHGFI_DISPLAYNAME | SHGFI_ICON|SHGFI_LARGEICON); filelist.InsertItem(col,(LPCTSTR)finder.GetFileName(),3); for (int j=0;jGetNextItem( -1, LVNI_SELECTED); //得到用于拖动时显示的图象列表 CPoint pt; pList->ClientToScreen( &pt ); m_pImageList = pList->CreateDragImage( nSelected, &pt); if( !m_pImageList ) return; m_isDragging = true; m_pImageList->BeginDrag( 0, CPoint(8,8) ); ClientToScreen( &pt ); m_pImageList->DragEnter ( NULL,pt ); SetCapture(); CListCtrl &filelist=GetListCtrl(); POSITION pos = filelist.GetFirstSelectedItemPosition (); int nItem=filelist.GetNextSelectedItem (pos); m_filename=filelist.GetItemText (nItem,0); m_fileCopy = m_curPath + m_filename; } void CMyFtpClientView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CMainFrame* mFrm = (CMainFrame*)AfxGetMainWnd(); localDirView *pEView = (localDirView *)(mFrm->m_splitterWnd2.GetPane(0,0)); CPoint pt = point; ClientToScreen(&pt); CRgn listRgn,treeRgn; CRect listRt,treeRt; GetCtrlRect(&listRt); pEView->GetCtrlRect(&treeRt); listRgn.CreateRectRgn(listRt.left,listRt.top, listRt.right,listRt.bottom); treeRgn.CreateRectRgn(treeRt.left,treeRt.top, treeRt.right,treeRt.bottom); if( m_isDragging && (listRgn.PtInRegion(pt) || treeRgn.PtInRegion(pt) ) ) { m_pImageList->DragMove(pt); } CListView::OnMouseMove(nFlags, point); } void CMyFtpClientView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CListView::OnLButtonUp(nFlags, point); ClientToScreen( &point); if( m_isDragging ) { m_isDragging = false; m_pImageList->EndDrag(); ReleaseCapture(); delete m_pImageList; CMainFrame* mFrm = (CMainFrame*)AfxGetMainWnd(); localDirView *pEView = (localDirView *)(mFrm->m_splitterWnd2.GetPane(0,0)); CPoint pt = point; CRgn treeRgn; CRect treeRt; pEView->GetCtrlRect(&treeRt); treeRgn.CreateRectRgn(treeRt.left,treeRt.top, treeRt.right,treeRt.bottom); CString fileDesc; fileDesc = pEView->g_path_selected + "\\" + m_filename; if( treeRgn.PtInRegion(pt)) { if(pEView->g_path_selected.Find(".",0) != -1) { return; } int resault = m_pFtpConnection->GetFile(m_fileCopy, fileDesc); pEView->Update(); } } } void CMyFtpClientView::GetCtrlRect(CRect *rt) { CListCtrl* pList; pList = &GetListCtrl(); pList->GetClientRect(rt); ClientToScreen(*rt); } void CMyFtpClientView::putFile(CString localPath,CString localFile) { CString descPath = m_curPath + localFile; if(m_pFtpConnection != NULL) { m_pFtpConnection->PutFile(localPath,descPath); } find(); }