DirView.cpp
上传用户:gzboli
上传日期:2013-04-10
资源大小:471k
文件大小:8k
- // DirView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "quickimage.h"
- #include "DirView.h"
- #include "DirFrm.h"
- #include "Global.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDirView
- extern CString g_strCurrentDir;
- IMPLEMENT_DYNCREATE(CDirView, CFormView)
- CDirView::CDirView()
- : CFormView(CDirView::IDD)
- {
- //{{AFX_DATA_INIT(CDirView)
- //}}AFX_DATA_INIT
- }
- CDirView::~CDirView()
- {
- }
- void CDirView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDirView)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDirView, CFormView)
- //{{AFX_MSG_MAP(CDirView)
- ON_NOTIFY(NM_RCLICK, IDC_TREE1, OnRclickTree1)
- ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE1, OnItemexpandingTree1)
- ON_WM_SIZE()
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
- ON_COMMAND(ID_DIR_UP, OnDirUp)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDirView diagnostics
- #ifdef _DEBUG
- void CDirView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CDirView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDirView message handlers
- void CDirView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- m_treeExplorer.SubclassDlgItem(IDC_TREE1, this);
- m_treeExplorer.PopulateTree();
- m_treeExplorer.EnableImages();
- // HTREEITEM hItem;
- // hItem = m_treeExplorer.GetNextItem(TVI_ROOT, TVGN_ROOT);
- // BuildPathFromTree(hItem);
- if(IsWindow(m_treeExplorer.GetSafeHwnd()))
- {
- CRect rc;
- GetClientRect(&rc);
- m_treeExplorer.MoveWindow(0, 0, rc.Width(), rc.Height());
- }
- }
- void CDirView::OnRclickTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- m_treeExplorer.FolderPopup(pNMHDR, pResult);
-
- *pResult = 0;
- }
- void CDirView::OnItemexpandingTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- m_treeExplorer.FolderExpanding(pNMHDR, pResult);
-
- *pResult = 0;
- }
- void CDirView::OnSize(UINT nType, int cx, int cy)
- {
- SetScrollSizes(MM_TEXT, CSize(cx, cy));
- CFormView::OnSize(nType, cx, cy);
-
- if(IsWindow(m_treeExplorer.GetSafeHwnd()))
- {
- m_treeExplorer.MoveWindow(0, 0, cx, cy);
- }
- }
- void CDirView::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- // TODO: Add your control notification handler code here
- CString strPath;
- if(m_treeExplorer.GetSelectedFolderPath(strPath))
- {
- CGlobal::ChangeDirectory(strPath);
- GetFileView()->ListFiles();
- }
- *pResult = 0;
- }
- CFileView* CDirView::GetFileView()
- {
- CWnd *pParent = GetParent();
- while(NULL != pParent)
- {
- if(pParent->IsKindOf(RUNTIME_CLASS(CDirFrame)))
- return (CFileView*)(((CDirFrame*)pParent)->m_wndSplitV.GetPane(0, 1));
-
- pParent = pParent->GetParent();
- }
- return NULL;
- }
- void CDirView::ExpendItem(LPCTSTR lpszItemText)
- {
- ASSERT(strlen(lpszItemText) > 0);
- HTREEITEM hSel = m_treeExplorer.GetSelectedItem();
- if(NULL == hSel)
- {
- return;
- }
-
- CString strItemText;
- m_treeExplorer.Expand(hSel, TVE_EXPAND);
-
- HTREEITEM hNext = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- if(NULL == hNext)
- {
- return;
- }
-
- while(NULL != hNext)
- {
- if(!GetItemFolderPath(strItemText, hNext))
- {
- return;
- }
-
- if(strItemText.CompareNoCase(lpszItemText) == 0)
- {
- break;
- }
- hNext = m_treeExplorer.GetNextItem(hNext, TVGN_NEXT);
- }
-
- if(NULL != hNext)
- {
- m_treeExplorer.SelectItem(hNext);
- // m_treeExplorer.Expand(hNext, TVE_EXPAND);
- }
- }
- void CDirView::SetItemText(LPCTSTR lpszOldText, LPCTSTR lpszNewText)
- {
- ASSERT(strlen(lpszOldText) > 0);
- ASSERT(strlen(lpszNewText) > 0);
- HTREEITEM hSel = m_treeExplorer.GetSelectedItem();
- if(NULL == hSel)
- {
- return;
- }
-
- CString strItemText;
- m_treeExplorer.Expand(hSel, TVE_EXPAND);
-
- HTREEITEM hNext = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- if(NULL == hNext)
- {
- return;
- }
-
- while(NULL != hNext)
- {
- if(!GetItemFolderPath(strItemText, hNext))
- {
- return;
- }
-
- if(strItemText.CompareNoCase(lpszOldText) == 0)
- {
- m_treeExplorer.SetItemText(hNext, lpszNewText);
- break;
- }
- hNext = m_treeExplorer.GetNextItem(hNext, TVGN_NEXT);
- }
- }
- void CDirView::DeleteChilds(LPCTSTR lpszItemText)
- {
- HTREEITEM hSel = m_treeExplorer.GetSelectedItem();
- if(NULL == hSel)
- {
- return;
- }
-
- if(NULL != lpszItemText)
- {
- CString strItemText;
- // m_treeExplorer.Expand(hSel, TVE_EXPAND);
- if(!GetItemFolderPath(strItemText, hSel))
- {
- return;
- }
- if(strItemText.CompareNoCase(lpszItemText) == 0)
- {
- goto Done;
- }
-
- hSel = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- if(NULL == hSel)
- {
- return;
- }
- while(NULL != hSel)
- {
- if(!GetItemFolderPath(strItemText, hSel))
- {
- return;
- }
- if(strItemText.CompareNoCase(lpszItemText) == 0)
- {
- break;
- }
- hSel = m_treeExplorer.GetNextItem(hSel, TVGN_NEXT);
- }
- }
-
- Done:
- if(NULL != hSel)
- {
- HTREEITEM hChild = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- while(NULL != hChild)
- {
- m_treeExplorer.DeleteItem(hChild);
- hChild = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- }
- }
- }
- void CDirView::DeleteItem(LPCTSTR lpszItemText)
- {
- ASSERT(strlen(lpszItemText) > 0);
-
- HTREEITEM hSel = m_treeExplorer.GetSelectedItem();
- if(NULL == hSel)
- {
- return;
- }
-
- CString strItemText;
- // m_treeExplorer.Expand(hSel, TVE_EXPAND);
- if(!GetItemFolderPath(strItemText, hSel))
- {
- return;
- }
- if(strItemText.CompareNoCase(lpszItemText) == 0)
- {
- m_treeExplorer.DeleteItem(hSel);
- }
-
- HTREEITEM hNext = m_treeExplorer.GetNextItem(hSel, TVGN_CHILD);
- if(NULL == hNext)
- {
- return;
- }
- while(NULL != hNext)
- {
- if(!GetItemFolderPath(strItemText, hNext))
- {
- return;
- }
- if(strItemText.CompareNoCase(lpszItemText) == 0)
- {
- m_treeExplorer.DeleteItem(hNext);
- return;
- }
- hNext = m_treeExplorer.GetNextItem(hNext, TVGN_NEXT);
- }
- }
- void CDirView::PoplateItem(LPCTSTR lpszItemText)
- {
- }
- BOOL CDirView::GetItemFolderPath(CString &strFolderPath, HTREEITEM hItem)
- {
- ASSERT(NULL != hItem);
-
- LPTVITEMDATA lptvid; //Long pointer to TreeView item data
- LPSHELLFOLDER lpsf2=NULL;
- static char szBuff[MAX_PATH];
- HRESULT hr;
- BOOL bRet=false;
-
- lptvid=(LPTVITEMDATA)m_treeExplorer.GetItemData(hItem);
-
- if (lptvid && lptvid->lpsfParent && lptvid->lpi)
- {
- hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
- 0,IID_IShellFolder,(LPVOID *)&lpsf2);
-
- if (SUCCEEDED(hr))
- {
- ULONG ulAttrs = SFGAO_FILESYSTEM;
-
- // Determine what type of object we have.
- lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
-
- if (ulAttrs & (SFGAO_FILESYSTEM))
- {
- if(SHGetPathFromIDList(lptvid->lpifq,szBuff)){
- strFolderPath = szBuff;
- bRet = true;
- }
- }
- }
-
- }
- if(lpsf2)
- lpsf2->Release();
-
- if(bRet)
- {
- if(strFolderPath.GetAt(strFolderPath.GetLength() -1) != '\')
- strFolderPath += _T("\");
- }
-
- return bRet;
- }
- void CDirView::OnDirUp()
- {
- MoveToUpFolder();
-
- }
- void CDirView::MoveToUpFolder()
- {
- HTREEITEM hSel = m_treeExplorer.GetSelectedItem();
- if(NULL == hSel)
- {
- return;
- }
- HTREEITEM hParent = m_treeExplorer.GetNextItem(hSel, TVGN_PARENT);
- if(NULL != hParent)
- {
- m_treeExplorer.SelectItem(hParent);
- m_treeExplorer.Expand(hParent, TVE_EXPAND);
- }
- }