FavoriteBar.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:5k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // FavoriteBar.cpp : implementation file
- //
- #include "stdafx.h"
- #include "IE.h"
- #include "FavoriteBar.h"
- #include <wininet.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFavoriteBar
- CFavoriteBar::CFavoriteBar()
- {
- this->favoritePath = "";
- }
- CFavoriteBar::~CFavoriteBar()
- {
- }
- BEGIN_MESSAGE_MAP(CFavoriteBar, CSizingControlBar)
- //{{AFX_MSG_MAP(CFavoriteBar)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFavoriteBar message handlers
- BOOL CFavoriteBar::Create( CFrameWnd * pParentWnd )
- {
- if( CSizingControlBar::Create( "收藏夹" , pParentWnd, CSize( 230 , 260 ) , FALSE , 1 ) )
- {
- this->SetBarStyle( this->GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- this->SetSCBStyle( SCBS_SIZECHILD );
- this->EnableDocking( CBRS_ALIGN_LEFT );
- pParentWnd->EnableDocking( CBRS_ALIGN_ANY );
- pParentWnd->DockControlBar( this , AFX_IDW_DOCKBAR_LEFT );
- this->m_tree.Create( WS_CHILD | WS_VISIBLE | TVS_SHOWSELALWAYS | TVS_TRACKSELECT | TVS_INFOTIP | WS_BORDER | WS_TABSTOP , CRect( 0 , 0 , 1 , 1 ) , this , IDC_TREE );
- //创建收藏夹
- this->GetFavoriteFolder( this->favoritePath );
- SHFILEINFO shFinfo;
- HIMAGELIST imglist = ( HIMAGELIST )SHGetFileInfo( "C:\" , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
- this->m_tree.SendMessage( TVM_SETIMAGELIST , (WPARAM )TVSIL_NORMAL , ( LPARAM )imglist );
- SHGetFileInfo( this->favoritePath , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
- int n = shFinfo.iIcon;
- SHGetFileInfo( this->favoritePath , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_OPENICON );
- HTREEITEM h = this->m_tree.InsertItem( "收藏夹" , n , shFinfo.iIcon );
- this->BuildFavorites( this->favoritePath , h );
- // ScrollBar( this->m_tree.GetSafeHwnd( ) );
- // this->m_tree.Expand( h , TVE_EXPAND );
- return TRUE;
- }
- return FALSE;
- }
- //取得收藏夹的路径
- void CFavoriteBar::GetFavoriteFolder( CString & strPath )
- {
- strPath = "";
- LPITEMIDLIST pidlFavorites = NULL;
- IMalloc * m_pMalloc = NULL;
- if( SUCCEEDED( SHGetMalloc( &m_pMalloc ) ) )
- {
- if( SHGetSpecialFolderLocation( NULL, CSIDL_FAVORITES, &pidlFavorites ) == NOERROR )
- {
- SHGetPathFromIDList( pidlFavorites , strPath.GetBufferSetLength( MAX_PATH ) );
- strPath.ReleaseBuffer( );
- }
- m_pMalloc->Free( pidlFavorites );
- m_pMalloc->Release();
- }
- }
- void CFavoriteBar::BuildFavorites( CString strPath , HTREEITEM hTree )
- {
- CFileFind find;
- if( strPath[ strPath.GetLength( ) - 1 ] != '\' )
- strPath += "\";
- strPath += "*.*";
- if( ! find.FindFile( strPath ) )
- return;
- CString name;
- int i , n , s;
- SHFILEINFO shFinfo;
- while( find.FindNextFile( ) )
- {
- if( find.IsDots( ) )
- continue;
- name = find.GetFileName( );
- if( ( i = name.ReverseFind( '.' ) ) != -1 )
- name = name.Left( i );
- if( find.IsDirectory( ) )
- {
- SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
- n = shFinfo.iIcon;
- SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_OPENICON );
- s = shFinfo.iIcon;
- HTREEITEM h = this->m_tree.InsertItem( name , n , s , hTree );
- BuildFavorites( find.GetFilePath( ) , h );
- }
- else
- {
- SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
- n = shFinfo.iIcon;
- SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_OPENICON );
- s = shFinfo.iIcon;
- this->m_tree.InsertItem( name , n ,s , hTree );
- }
- }
- }
- void CFavoriteBar::GetCurURL( CString & url )
- {
- this->GetCurFullName( url );
- if( url.IsEmpty( ) )
- return;
- CString path( url );
- url.Empty( );
- ::GetPrivateProfileString(_T("InternetShortcut"), _T("URL") , _T(""), url.GetBufferSetLength( INTERNET_MAX_PATH_LENGTH ), INTERNET_MAX_PATH_LENGTH , path );
- url.ReleaseBuffer( );
- }
- void CFavoriteBar::GetCurFullName( CString & name )
- {
- name.Empty( );
- CPoint pt;
- ::GetCursorPos( &pt );
- this->m_tree.ScreenToClient( &pt );
- UINT flag;
- HTREEITEM item = this->m_tree.HitTest( pt , &flag );
- if( ! item || this->m_tree.Expand( item , TVE_EXPAND ) )
- return;
- name = this->m_tree.GetItemText( item );
- while( item )
- {
- item = this->m_tree.GetParentItem( item );
- if( item )
- name = this->m_tree.GetItemText( item ) + "\" + name;
- }//去掉"收藏夹"
- name.Delete( 0 , 7 );
- name = this->favoritePath + "\" + name + ".url";
- }