【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,FtpTrCtl.cpp,希望对大家有所帮助!
// FTPTrCtl.cpp : implementation file
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "MyFtp.h"
#include "FTPtrCtl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl
CMyTreeCtrl::CMyTreeCtrl()
{
// m_pFtpConnection holds a pointer to an FTP connection
// that is maintained by CFTPTREEDlg.
m_pFtpConnection = NULL;
}
CMyTreeCtrl::~CMyTreeCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyTreeCtrl, CTreeCtrl)
//{{AFX_MSG_MAP(CMyTreeCtrl)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl message handlers
void CMyTreeCtrl::OnDestroy()
{
CImageList *pimagelist;
pimagelist = GetImageList(TVSIL_NORMAL);
//pimagelist->DeleteImageList();
//delete pimagelist;
}
void CMyTreeCtrl::PopulateTree(CFtpConnection* pConnection, const CString& strDir)
{
CWaitCursor cursor; // this will automatically display a wait cursor
// Make sure tree is empty before (re)populating it
DeleteAllItems();
// If CFtpConnection is NULL, display error in tree
if (!pConnection)
{
// change style -- remove TVS_LINESATROOT if it is currently set
ModifyStyle(TVS_LINESATROOT, 0);
TV_INSERTSTRUCT tvstruct;
tvstruct.hParent = NULL;
tvstruct.hInsertAfter = TVI_FIRST;
tvstruct.item.iImage = 0;
tvstruct.item.iSelectedImage = 0;
tvstruct.item.pszText = _T("An FTP connection has not been established.");
tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
InsertItem(&tvstruct);
m_pFtpConnection = NULL;
}
else
{
m_pFtpConnection = pConnection;
CString cstr = _T("/"); // look at the root directory first
// insert the the root into the tree struct
TV_INSERTSTRUCT tvstruct;
tvstruct.hParent = NULL;
tvstruct.hInsertAfter = TVI_LAST;
tvstruct.item.iImage = 1;
tvstruct.item.iSelectedImage = 1;
tvstruct.item.pszText = _T("/");
tvstruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
HTREEITEM hThisItem = InsertItem(&tvstruct);
// the root dir needs to think it has children for Expand() to work
// Expand() will call ExploreDir() to find the root's real children
tvstruct.hParent = hThisItem;
InsertItem(&tvstruct);
Expand(GetRootItem(), TVE_EXPAND);
// if the root has no real children, make sure TVS_LINESATROOT is not set
if (!ItemHasChildren(GetRootItem()))
{
ModifyStyle(TVS_LINESATROOT, 0);
return;
}
// otherwise, there are children, so set TVS_LINESATROOT
ModifyStyle(0, TVS_LINESATROOT);
if (!strDir)
return;
// expand as far as was indicated in strDir
int nIndex;
CString strTemp;
CString strSrc = strDir;
HTREEITEM hTI = GetRootItem();
while (!strSrc.IsEmpty())
{
nIndex = strSrc.Find(_T("/"));
if (nIndex < 0)
{
cstr = strSrc;
strSrc.Empty();
}
else if (nIndex > 0)
{ // the "/" trailing the directory name is not included
cstr = strSrc.Left(nIndex);
strTemp = strSrc.Right(strSrc.GetLength() - (nIndex+1));
strSrc = strTemp;
}
if(!cstr.IsEmpty() && (nIndex != 0))
{
// cstr now has the name o