第四步:使用类库、组件
1.左边的目录树对应的类是CLeftView,修改之。
class CLeftView : public CView/*CTreeView*/ { ... // Attributes public: CShellTree m_TreeCtrl;// use shell tree control ... // Generated message map functions protected: //{{AFX_MSG(CLeftView) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult); //}}AFX_MSG DECLARE_MESSAGE_MAP() ... };
(1)将其父类由CTreeView改为CView,原因后述。
(2)加入CShellTree类的成员变量m_TreeCtrl,目录树的具体内容就是由它实现的。
(3)增加消息响应函数OnCreate(),在其中把m_TreeCtrl创建起来。
(4)增加消息响应函数OnSize(),使m_TreeCtrl总是占满CLeftView的区域。
(5)增加消息响应函数OnItemexpanding(),在此响应展开目录的操作。如果CLeftView的父类是CTreeView的话,将不能得到希望的结果,这就是(1)中把父类改为CView的原因。
(6)增加消息响应函数OnSelchanged(),在此响应点击目录的操作。
具体修改请看源文件leftview.h和leftview.cpp,都很简单。
2.右边的文件列表对应的类是CSimpleBrowseView,修改之。
class CSimpleBrowseView : public CView/*CListView*/ { ... // Attributes public: CThumbListCtrl m_ThumbListCtrl; // use thumb list control // Operations public: void FormatList(CString csPath);
// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSimpleBrowseView) protected: virtual void OnInitialUpdate(); // called first time after construct //}}AFX_VIRTUAL ... // Generated message map functions protected: //{{AFX_MSG(CSimpleBrowseView) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnSize(UINT nType, int cx, int cy); //}}AFX_MSG DECLARE_MESSAGE_MAP() ... };
(1)将其父类由CListView改为CView,原因和上面的类似。
(2)加入CThumbListCtrl类的成员变量m_ThumbListCtrl,文件列表的具体内容就是由它实现的。
(3)增加消息响应函数OnCreate(),在其中把m_ThumbListCtrl创建起来,并初始化为缩图显示风格。
(4)增加消息响应函数OnSize(),使m_ThumbListCtrl总是占满CSimpleBrowseView的区域。
(5)在OnInitialUpdate()中创建文件列表的栏目,调用CThumbListCtrl::BuildColumns()。
(6)增加函数FormatList(),它被CLeftView::OnSelchanged()调用,它则转而调用CThumbListCtrl::BrowseFolder()。点击左边的目录树,右边的文件列表跟着改变,就是通过这一个函数来实现的。
具体修改请看源文件simplebrowseview.h和simplebrowseview.cpp,都很简单。  
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
2/2 首页 上一页 1 2 |