首页 随笔 乐走天涯 程序资料 评论中心 Tag 论坛 其他资源 搜索 联系我 关于 RSS

用对话框浏览显示目录的树型结构


日期: 2002-01-03 14:00 | 联系我 | 关注我: Telegram, Twitter

本程序引入CShellTree、CFileName、CFilePidl等类,用于实现在对话框中显示外壳命名空间,参见下图。

 

CShellTree派生于CTreeCtrl,其函数包括:

// Initializes the treeview with "mycomputer" etc void PopulateTree(); // Initializes the treeview starting with a special folder as root // See the SHGetSpecialFolderLocation() for constants and descriptions void PopulateTree(int SpecialFolderID); // Must be called from OnItemExpanding(), message TVN_ITEMEXPANDING void OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult); // Frees memory allocated for the shell object. message TVN_DELETEITEM void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult); // Must be called from OnRclick(). message NM_RCLICK void GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult); // Must be called from OnSelChanged(), message TVN_SELCHANGED BOOL OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath); // Enables Folder Images in the tree control. void EnableImages(); // Retrieves the path of the Selected Folder. BOOL GetSelectedFolderPath(CString &szFolderPath); // Opens the folder of the specified path. Does it's own error checking void TunnelTree(CString szFindPath)

使用上述类的方法如下:

  1. 在工程中包含shelltree.cpp和shelltree.h, shellpidl.cpp和shellpidl.h,filename.cpp和 filename.h

    #include "Shelltree.h" #include "shellpidl.h" #include "filename.h"

  2. 创建对话框。

  3. 在对话框中添加ShellTree类成员:

    CShellTree* m_TreeCtl;

  4. 在OnInitDialog()中,初始化树视控件:

    BOOL CTreeSelect::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_TreeCtl = (CShellTree*) GetDlgItem(IDC_SHELLTREE); //replace IDC_SHELLTREE with your control's ID ASSERT(m_TreeCtl); m_TreeCtl->EnableImages(); //enable images m_TreeCtl->PopulateTree(); //populate for the with Shell Folders for the first time return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

    注意:CShellTree具备处理图像的能力,不用包含ImageList到CShellTree。

    调用

    m_TreeCtl->EnableImages();

    创建和附加图像列表到树视控件,下面代码初始化树视控件:

    m_TreeCtl->PopulateTree();

  5. 必须创建回调TVN_ITEMEXPANDING的处理函数,否则,树视将会死掉。

    void CTreeSelect::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; // TODO: Add your control notification handler code here m_TreeCtl->FolderExpanding(pNMHDR,pResult); *pResult = 0; }

    FolderExpanding()方法添加目录节点到树视控件中,其与OnItemExpanding具有相同的参数。

  6. 如果需要弹出菜单激活,创建OnRclick(),其弹出与Windows Explorer一样:

    void CTreeSelect::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here m_TreeCtl->FolderPopup(pNMHDR,pResult); *pResult = 0; }

>>> DOWN !!! >>>下载源代码及演示程序


 文章评论
目前没有任何评论.

↓ 快抢占第1楼,发表你的评论和意见 ↓

发表你的评论
如果你想针对此文发表评论, 请填写下列表单:
姓名: * 必填 (Twitter 用户可输入以 @ 开头的用户名, Steemit 用户可输入 @@ 开头的用户名)
E-mail: 可选 (不会被公开。如果我回复了你的评论,你将会收到邮件通知)
反垃圾广告: 为了防止广告机器人自动发贴, 请计算下列表达式的值:
8 x 3 + 1 = * 必填
评论内容:
* 必填
你可以使用下列标签修饰文字:
[b] 文字 [/b]: 加粗文字
[quote] 文字 [/quote]: 引用文字

 
首页 随笔 乐走天涯 猎户星 Google Earth 程序资料 程序生活 评论 Tag 论坛 资源 搜索 联系 关于 隐私声明 版权声明 订阅邮件

程序员小辉 建站于 1997 ◇ 做一名最好的开发者是我不变的理想。
Copyright © XiaoHui.com; 保留所有权利。