赞助

Duilib实现 Windows资源管理器前进后退原理

一、用两个vector保存路径

  vector<wstring> vctBacks;//保存后退路径的集合

  vector<wstring> vctForwards//保存前进路径集合

  CButtonUI*  pBackbtn;//后退按钮

  CButtonUI* pForwardbtn;//前进按钮

1.程序初始化时,两个按钮不可用状态

2.当点击一系列目录后,后退集合把这些路径保存,后退按钮设为可用状态

3.当点击后退按钮,把vctBacks最后一个元素取出来 wstring temp = vctBacks.back(),放进前进集合里 vctForwards.push_back(temp),然后后退集合删除掉最后一个 vctBacks.pop_back()

4.再点击前进按钮,把vctForwards最后一个元素取出来 wstring temp = vctForwards.back(),,放进前进集合里 vctBacks.push_back(temp),然后后退集合删除掉最后一个 vctForwards.pop_back()

5.若前进集合还有一个元素时,取出元素push到后退集合里。然后把前进按钮设为不可用;若后退集合还有一个元素时,取出元素push到前几集合里,然后把后退按钮设为不可用

 

  1 void OnClickBtnForward()
  2 {
  3     if (m_vctForwards.size() > 0)
  4     {
  5         if (m_vctForwards.size() == 1)
  6         {
  7             wstring wstr = m_vctForwards.back();
  8             CListLabelElementUI* pElement = (CListLabelElementUI*)(m_pLeftTree->FindSubControl(wstr.c_str()));
  9 
 10             if (pElement)
 11             {
 12                 pElement->Select();
 13             }
 14             
 15             m_vctBacks.push_back(wstr);
 16             m_vctForwards.pop_back();
 17 
 18             if (m_vctForwards.empty())//在此判断有点多余
 19             {
 20                 m_pForwardbtn->SetEnabled(false);
 21             }
 22 
 23             if (!m_vctBacks.empty())
 24             {
 25                 m_pBackbtn->SetEnabled(true);
 26             }
 27             
 28             m_pPath->SetText(wstr.c_str());
 29             m_pFileList->RemoveAll();
 30             InitFileList(wstr.c_str());
 31             return;
 32         }
 33         else
 34         {
 35             wstring  temp = m_vctForwards.back();
 36             m_vctBacks.push_back(temp);
 37             m_vctForwards.pop_back();
 38             temp = m_vctBacks.back();
 39 
 40             CListLabelElementUI* pElement = (CListLabelElementUI*)(m_pLeftTree->FindSubControl(temp.c_str()));
 41             if (pElement != NULL)
 42             {
 43                 pElement->Select();
 44             }
 45 
 46             if (!m_vctBacks.empty())
 47             {
 48                 m_pBackbtn->SetEnabled(true);
 49             }
 50 
 51             m_pFileList->RemoveAll();
 52             InitFileList(temp.c_str());
 53             m_pPath->SetText(temp.c_str());
 54         }
 55     }
 56 }
 57 
 58 void OnClickBtnBack()
 59 {
 60     if (m_vctBacks.size() > 0)
 61     {
 62 
 63         if (m_vctBacks.size() == 1)
 64         {
 65             wstring wstr = m_vctBacks.back();
 66             CListLabelElementUI* pElement = (CListLabelElementUI*)(m_pLeftTree->FindSubControl(wstr.c_str()));
 67 
 68             if (pElement)
 69             {
 70                 pElement->Select();
 71             }
 72             m_vctForwards.push_back(wstr);
 73             m_vctBacks.pop_back();
 74             m_pPath->SetText(_T(""));
 75             m_pBackbtn->SetEnabled(false);
 76             m_pFileList->RemoveAll();
 77             return;
 78         }
 79         else
 80         {
 81             wstring temp = m_vctBacks.back();
 82             m_vctForwards.push_back(temp);//只要执行这行代码,前进按钮就可用
 83             if (!m_vctForwards.empty())
 84             {
 85                 m_pForwardbtn->SetEnabled(true);
 86             }
 87             m_vctBacks.pop_back();
 88             temp = m_vctBacks.back();
 89 
 90             CListLabelElementUI* pElement = (CListLabelElementUI*)(m_pLeftTree->FindSubControl(temp.c_str()));
 91 
 92             if (pElement != NULL)
 93             {
 94                 pElement->Select();
 95             }
 96             m_pFileList->RemoveAll();
 97             InitFileList(temp.c_str());
 98             m_pPath->SetText(temp.c_str());
 99         }    
100     }
101 }

 

posted @ 2016-03-31 16:20  车臣  阅读(714)  评论(0编辑  收藏  举报