DriverBar.cpp
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:4k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. // DriverBar.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "File.h"
  5. #include "DriverBar.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CDriverBar
  13. CDriverBar::CDriverBar()
  14. {
  15. }
  16. CDriverBar::~CDriverBar()
  17. {
  18. }
  19. BEGIN_MESSAGE_MAP(CDriverBar, CSizingControlBar)
  20. //{{AFX_MSG_MAP(CDriverBar)
  21. //}}AFX_MSG_MAP
  22. ON_NOTIFY( TVN_ITEMEXPANDING , IDC_TREE , OnItemexpandingTree )
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CDriverBar message handlers
  26. BOOL CDriverBar::Create( CFrameWnd * pParentWnd )
  27. {
  28. if( CSizingControlBar::Create( "资源管理器" , pParentWnd , CSize( 230 , 260 ) , TRUE , 1 ) )
  29. {
  30. this->SetBarStyle( this->GetBarStyle( ) | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
  31. this->EnableDocking( CBRS_ALIGN_LEFT );
  32. this->SetSCBStyle( SCBS_SIZECHILD );
  33. pParentWnd->EnableDocking( CBRS_ALIGN_ANY );
  34. pParentWnd->DockControlBar( this , AFX_IDW_DOCKBAR_LEFT );
  35. this->m_tree.Create( WS_CHILD | WS_VISIBLE | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_TRACKSELECT | TVS_INFOTIP | TVS_FULLROWSELECT | WS_BORDER | WS_TABSTOP , CRect( 0 , 0 , 1 , 1 ) , this , IDC_TREE );
  36.         //设定系统图标
  37. SHFILEINFO shFinfo;
  38. HIMAGELIST imglist = ( HIMAGELIST )SHGetFileInfo( "C:\" , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
  39. this->m_tree.SendMessage( TVM_SETIMAGELIST , (WPARAM )TVSIL_NORMAL , ( LPARAM )imglist );
  40. this->Init( );
  41. // ScrollBar( this->m_tree.GetSafeHwnd( ) );
  42. return TRUE;
  43. }
  44. return FALSE;
  45. }
  46. void CDriverBar::Init( void )
  47. {
  48. char drivers[ MAX_PATH ];
  49. ::GetLogicalDriveStrings( MAX_PATH , drivers );
  50. char * now = drivers;
  51. int n , s;
  52. SHFILEINFO shFinfo;
  53. CFileFind find;
  54. while( strlen( now ) )
  55. {
  56. SHGetFileInfo( now , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
  57. n = shFinfo.iIcon;
  58. SHGetFileInfo( now , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_OPENICON | SHGFI_DISPLAYNAME );
  59. s = shFinfo.iIcon;
  60. HTREEITEM h = this->m_tree.InsertItem( shFinfo.szDisplayName , n , s );
  61. if( find.FindFile( ( CString )now + "*.*" ) )
  62. this->m_tree.InsertItem( "" , -1 , -1 , h );
  63. now += strlen( now ) + 1;
  64. }
  65. }
  66. void CDriverBar::Expand( void )
  67. {
  68. CPoint pt;
  69. ::GetCursorPos( &pt );
  70. this->m_tree.ScreenToClient( &pt );
  71. UINT flag;
  72. HTREEITEM item = this->m_tree.HitTest( pt , &flag );
  73. if( item )
  74. {
  75. HTREEITEM h = this->m_tree.GetChildItem( item );
  76. if( h )
  77. this->m_tree.DeleteItem( h );
  78. CString path;
  79. this->GetFullPath( path , item );
  80. if( path.IsEmpty( ) )
  81. return;
  82. int n , s;
  83. SHFILEINFO shFinfo;
  84. CFileFind find;
  85. if( ! find.FindFile( path + "\*.*" ) )
  86. return;
  87. while( find.FindNextFile( ) )
  88. {
  89. if( find.IsDots( ) )
  90. continue;
  91. SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
  92. n = shFinfo.iIcon;
  93. SHGetFileInfo( find.GetFilePath( ) , 0 , &shFinfo , sizeof( shFinfo ) , SHGFI_SYSICONINDEX | SHGFI_OPENICON | SHGFI_DISPLAYNAME );
  94. s = shFinfo.iIcon;
  95. h = this->m_tree.InsertItem( find.GetFileName( ) , n , s , item );
  96. if( find.IsDirectory( ) )
  97. this->m_tree.InsertItem( "" , -1 , -1 , h );
  98. }
  99. }
  100. }
  101. void CDriverBar::OnItemexpandingTree( NMHDR* pNMHDR , LRESULT * pResult )
  102. {
  103. NM_TREEVIEW * pNMTreeView = ( NM_TREEVIEW * )pNMHDR;
  104. if( pNMTreeView->action == TVE_EXPAND )
  105. this->Expand( );
  106. *pResult = 0;
  107. }
  108. void CDriverBar::GetFullPath( CString & path , HTREEITEM hItem )
  109. {
  110. if( hItem == NULL )
  111. hItem = this->m_tree.GetSelectedItem( );
  112. CString text;
  113. while( hItem )
  114. {
  115. text = this->m_tree.GetItemText( hItem ) + "\" + text;
  116. hItem = this->m_tree.GetParentItem( hItem );
  117. }
  118. int i = text.Find( ':' , 0 );
  119. path.Format( "%c:\%s" , text[ i - 1 ] , text.Mid( i + 3 , text.GetLength( ) - i - 4 ) );
  120. }