FtpDirList.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:9k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // FtpDirList.cpp : implementation file
- //
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "FtpDirList.h"
- #include "SortStringArray.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirList
- CFtpDirList::CFtpDirList()
- {
- m_nItem = 0 ;
- }
- CFtpDirList::~CFtpDirList()
- {
- m_ImageList.Detach( ) ;
- m_ImageList.m_hImageList = NULL ;
- }
- BEGIN_MESSAGE_MAP(CFtpDirList, CListCtrl)
- //{{AFX_MSG_MAP(CFtpDirList)
- ON_WM_CREATE()
- ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
- ON_WM_KEYDOWN()
- ON_WM_DESTROY()
- ON_WM_RBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFtpDirList message handlers
- /***************************************************
- ** @Description:
- ** Get system default image list handle .
- **
- ** @Note:
- **
- ** @Return: success true , else false .
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CFtpDirList::GetSysImgList()
- {
- SHFILEINFO shFinfo;
- HIMAGELIST hImgList = NULL;
- hImgList = (HIMAGELIST)SHGetFileInfo( "C:\",
- 0,
- &shFinfo,
- sizeof( shFinfo ),
- SHGFI_SYSICONINDEX |
- SHGFI_SMALLICON );
- if ( !hImgList )
- {
- return FALSE;
- }
- m_ImageList.m_hImageList = hImgList ;
- SetImageList( &m_ImageList , LVSIL_SMALL ) ;
- //get directory icon index ;
- char szPath[MAX_PATH] ;
- if( GetSystemDirectory( szPath , MAX_PATH ) == 0 )
- {
- m_DirIconIndex = 5 ;
- return true ;
- }
- SHFILEINFO shFileInfo ;
- CString strTemp = szPath ;
- //add ''
- if ( strTemp.Right(1) != '\' )
- strTemp += "\";
- //get the system icon index .
- if ( !SHGetFileInfo( strTemp,
- 0,
- &shFileInfo,
- sizeof( shFileInfo ),
- SHGFI_ICON | SHGFI_SMALLICON |
- SHGFI_TYPENAME |SHGFI_DISPLAYNAME ) )
- {
- return false ;
- }
- m_DirIconIndex = shFileInfo.iIcon;
- // we only need the index from the system image list
- DestroyIcon( shFileInfo.hIcon );
- return TRUE; // OK
- }
- int CFtpDirList::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CListCtrl::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- InitList( ) ;
- GetSysImgList( ) ;
- return 0;
- }
- /***********************************************************
- ** @Description:
- ** Init the list column .
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- BOOL CFtpDirList::InitList()
- {
- RECT rect ;
- GetClientRect( &rect ) ;
- int iLength = ( rect.right - rect.left ) / 6 ;
- //insert Column
- InsertColumn( 0 , "名称" , LVCFMT_LEFT , iLength * 2 ) ;
- InsertColumn( 1 , "大小" , LVCFMT_RIGHT , iLength ) ;
- InsertColumn( 2 , "类型" , LVCFMT_LEFT, iLength ) ;
- InsertColumn( 3 , "时间" , LVCFMT_LEFT, iLength ) ;
- InsertColumn( 4 , "日期" , LVCFMT_LEFT, iLength ) ;
- InsertColumn( 5 , "属性" , LVCFMT_LEFT, iLength ) ;
- // AddItem( "abc" , "abc" , "abc" , "abc" , "abc" ) ;
- return true ;
- }
- /***********************************************************
- ** @Description:
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- BOOL CFtpDirList::AddItem(LPCTSTR szName, LPCTSTR szSize, LPCTSTR szDate,
- LPCTSTR szTime, LPCTSTR szAttrib , LPCTSTR szType )
- {
- return true ;
- }
- /***********************************************************
- ** @Description:
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- void CFtpDirList::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
- ::PostMessage( m_hParentWnd , FTP_LIST_DBCLICK_MSG , 0 , 0 );
- *pResult = 0;
- }
- /***********************************************************
- ** @Description:
- ** delete all list item . and reset the item count.
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- BOOL CFtpDirList::DelAllItem()
- {
- m_nItem = 0 ;
- return DeleteAllItems( ) ;
- }
- /***********************************************************
- ** @Description:
- ** Add a item to list ctrl .
- **
- ** @Note:
- ** FTPITEM* pItem : item info.
- **
- ** @Return: true .
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- BOOL CFtpDirList::AddItem(FTPITEM *pItem)
- {
- FTPITEM* pCur ;
- CSortStringArray strDirArray ;
- CSortStringArray strFileArray ;
- //empty the list.
- DeleteAllItems( ) ;
- //init the array .
- strDirArray.RemoveAll() ;
- strFileArray.RemoveAll( ) ;
- //beacuse want sort the item .
- pCur = pItem ;
- while( pCur->pNext != NULL )
- {
- if( pCur->dwType == 1 )
- {
- //if directory
- strDirArray.Add( pCur->szName ) ;
- }
- else
- {
- //if files .
- int index = 0 ;
- index = strFileArray.Add( pCur->szName ) ;
- }
- pCur = pCur->pNext ;
- }
- //sort the item .
- strDirArray.Sort( ) ;
- strFileArray.Sort( ) ;
- //insert directory .
- int i = 0 ;
- for( i = 0 ; i < strDirArray.GetSize( ) ; i ++ )
- {
- pCur = pItem ;
- while( pCur->pNext != NULL )
- {
- if( strcmp( strDirArray.GetAt( i ) , pCur->szName ) == 0 )
- {
- InsertItem( LVIF_TEXT|LVIF_IMAGE , m_nItem , pCur->szName , 0 , 0 , m_DirIconIndex , 0 ) ;
- SetItemText( m_nItem , 1 , pCur->szSize ) ;
- SetItemText( m_nItem , 2 , "DIR" ) ;
- SetItemText( m_nItem , 3 , pCur->szTime ) ;
- SetItemText( m_nItem , 4 , pCur->szDate ) ;
- SetItemText( m_nItem , 5 , pCur->szAttrib ) ;
- m_nItem ++ ;
- break ;
- }
- pCur = pCur->pNext ;
- }
- }
- //insert file.
- for( i = 0 ; i < strFileArray.GetSize() ; i ++ )
- {
- pCur = pItem ;
- while( pCur->pNext != NULL )
- {
- if( strcmp( strFileArray.GetAt( i ) , pCur->szName ) == 0 )
- {
- int iIconIndex ;
- iIconIndex = GetIconIndex( pCur->szName ) ;
- InsertItem( LVIF_TEXT|LVIF_IMAGE , m_nItem , pCur->szName , 0 , 0 , iIconIndex , 0 ) ;
- SetItemText( m_nItem , 2 , "" ) ;
- SetItemText( m_nItem , 1 , pCur->szSize ) ;
- SetItemText( m_nItem , 3 , pCur->szTime ) ;
- SetItemText( m_nItem , 4 , pCur->szDate ) ;
- SetItemText( m_nItem , 5 , pCur->szAttrib ) ;
- m_nItem ++ ;
- break ;
- }
- pCur = pCur->pNext ;
- }
- }
- return true ;
- }
- /***********************************************************
- ** @Description:
- ** Get the file default icon index , which in system
- ** default image list .
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** @e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- *************************************************************/
- int CFtpDirList::GetIconIndex(LPSTR szName)
- {
- //only need the file extend name .
- char driver[MAX_PATH] , dir[MAX_PATH] , name[MAX_PATH] , ext[MAX_PATH] ;
- _splitpath( szName , driver , dir , name , ext ) ;
- SHFILEINFO sfi;
- ZeroMemory(&sfi,sizeof(sfi));
- SHGetFileInfo( ext ,
- FILE_ATTRIBUTE_NORMAL,
- &sfi,
- sizeof(sfi),
- SHGFI_USEFILEATTRIBUTES|SHGFI_ICON);
- DestroyIcon( sfi.hIcon ) ;
- return sfi.iIcon ;
- }
- void CFtpDirList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- switch( nChar )
- {
- case VK_F5 :
- case VK_DELETE :
- case VK_F2 :
- case VK_BACK:
- case VK_RETURN :
- {
- ::PostMessage( m_hParentWnd , FTP_LIST_KEY_EVENT_MSG , nChar , 0 ) ;
- }
- break ;
- default :
- break ;
- }
- CListCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CFtpDirList::OnDestroy()
- {
- //must deatch the system image list handle .
- //if not ,the system image will be destroy.
- SetImageList( NULL , LVSIL_SMALL ) ;
- m_ImageList.Detach( ) ;
- CListCtrl::OnDestroy();
- // TODO: Add your message handler code here
- }
- void CFtpDirList::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- ::PostMessage( m_hParentWnd , FTP_LIST_RCLK_MSG , 0 , 0 ) ;
- CListCtrl::OnRButtonDown(nFlags, point);
- }
- BOOL CFtpDirList::SelectAllItem()
- {
- int iCount = GetItemCount( ) ;
- if( iCount == 0 )
- return true ;
- for( int i = 0 ; i < iCount ; i ++ )
- {
- SetItemState( i , LVIS_SELECTED , LVIS_SELECTED ) ;
- }
- return true ;
- }