基于MFC的FTP客户端demo


支持文件上传下载,以及在线浏览目录。等功能
资源截图
代码片段和文件信息
// FileTree.cpp : implementation file
//

#include “stdafx.h“
#include “FtpClient.h“
#include “FileTree.h“

//add new
#include “MainFrm.h“
#include “FtpClientView.h“
#include “MsgShow.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFileTree

IMPLEMENT_DYNCREATE(CFileTree CTreeView)

CFileTree::CFileTree()
{
tree = &GetTreeCtrl();
m_bDragging = false;
}

CFileTree::~CFileTree()
{
}


BEGIN_MESSAGE_MAP(CFileTree CTreeView)
//{{AFX_MSG_MAP(CFileTree)
ON_NOTIFY_REFLECT(TVN_BEGINDRAG OnBegindrag)
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFileTree drawing

void CFileTree::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CFileTree diagnostics

#ifdef _DEBUG
void CFileTree::AssertValid() const
{
CTreeView::AssertValid();
}

void CFileTree::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFileTree message handlers
VOID CFileTree::deleteItem()
{
tree->DeleteAllItems();
}

//注:函数只适用于遍历目录,而非查找文件
VOID CFileTree::BrowseDir(CString strDirHTREEITEM hParent)
{
CFileFind fFind;
CString strFileName;

if(strDir.Right(2) != “\“) //important!
{
strDir += “\*.*“;
}

BOOL IsTrue = fFind.FindFile(strDir);

while(IsTrue)
{
IsTrue = fFind.FindNextFile();

if( fFind.IsDirectory() && !fFind.IsDots() )
{
CString strPath = fFind.GetFilePath();
strFileName = fFind.GetFileName();

HTREEITEM hChild = tree->InsertItem(strFileName00hParent);

BrowseDir(strPathhChild);
}
else  if( !fFind.IsDirectory() && !fFind.IsDots() )
{
strFileName = fFind.GetFileName();

tree->InsertItem(strFileName11hParent);
}
}

fFind.Close();
}


BOOL CFileTree::PreCreateWindow(CREATESTRUCT& cs) 
{
// TODO: Add your specialized code here and/or call the base class

//add new 更改控件的style
cs.style |= TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_EDITLABELS;

return CTreeView::PreCreateWindow(cs);
}

void CFileTree::OnInitialUpdate() 
{
CTreeView::OnInitialUpdate();

// TODO: Add your specialized code here and/or call the base class
//获取图标句柄
HICON hicon1 = AfxGetApp()->LoadIcon(IDI_ICON1);
HICON hicon2 = AfxGetApp()->LoadIcon(IDI_ICON2);

//创建图标列表
m_lpImagelist.Create(1616ILC_COLOR1622);
m_lpImagelist.Add(hicon1);
m_lpImagelist.Add(hicon2);

//关联图像列表
tree->SetImageList(&m_lpImagelistTVSIL_NORMAL);
}

void CFileTree::OnBegindrag(NMHDR* pNMHDR LRESULT* pResult) 
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      42945  2013-03-28 16:03  FtpClientDebugFileTree.obj

     文件          0  2013-03-28 16:03  FtpClientDebugFileTree.sbr

     文件    5530624  2013-03-28 16:22  FtpClientDebugFtpClient.bsc

     文件     143456  2013-03-28 16:22  FtpClientDebugFtpClient.exe

     文件     452552  2013-03-28 16:22  FtpClientDebugFtpClient.ilk

     文件      25470  2013-01-12 16:06  FtpClientDebugFtpClient.obj

     文件    7011184  2013-01-12 10:48  FtpClientDebugFtpClient.pch

     文件     623616  2013-03-28 16:22  FtpClientDebugFtpClient.pdb

     文件       9640  2013-01-12 16:06  FtpClientDebugFtpClient.res

     文件          0  2013-01-12 16:06  FtpClientDebugFtpClient.sbr

     文件      14871  2013-01-12 10:48  FtpClientDebugFtpClientDoc.obj

     文件          0  2013-01-12 10:48  FtpClientDebugFtpClientDoc.sbr

     文件      43309  2013-03-28 16:22  FtpClientDebugFtpClientView.obj

     文件          0  2013-03-28 16:22  FtpClientDebugFtpClientView.sbr

     文件      33198  2013-01-14 11:12  FtpClientDebugMainFrm.obj

     文件          0  2013-01-14 11:13  FtpClientDebugMainFrm.sbr

     文件      19915  2013-01-12 13:32  FtpClientDebugMsgShow.obj

     文件          0  2013-01-12 13:44  FtpClientDebugMsgShow.sbr

     文件     105654  2013-01-12 13:31  FtpClientDebugStdAfx.obj

     文件    1376875  2013-01-12 13:31  FtpClientDebugStdAfx.sbr

     文件     246784  2018-08-15 13:13  FtpClientDebugvc60.idb

     文件     413696  2013-03-28 16:22  FtpClientDebugvc60.pdb

     文件       6999  2013-03-28 16:03  FtpClientFileTree.cpp

     文件       2155  2013-01-12 11:08  FtpClientFileTree.h

     文件      31568  2018-08-15 13:09  FtpClientFtpClient.aps

     文件       2876  2018-08-15 13:09  FtpClientFtpClient.clw

     文件       4263  2013-01-10 09:17  FtpClientFtpClient.cpp

     文件       5045  2013-01-11 18:21  FtpClientFtpClient.dsp

     文件        543  2013-01-10 09:18  FtpClientFtpClient.dsw

     文件       1389  2013-01-10 09:17  FtpClientFtpClient.h

............此处省略28个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)