我怎样才能创建一个类似Microsoft apps的树状视图 虽然我在开发一个应用程序,但是我想添加一棵树,它有一个特定的外观,我成功地做到了这一点,但是我所拥有的并不是我的客户想要的,应用程序是用MFC和C++开发的。

我怎样才能创建一个类似Microsoft apps的树状视图 虽然我在开发一个应用程序,但是我想添加一棵树,它有一个特定的外观,我成功地做到了这一点,但是我所拥有的并不是我的客户想要的,应用程序是用MFC和C++开发的。,c++,windows,winapi,mfc,window,C++,Windows,Winapi,Mfc,Window,我的应用程序如下所示: CRect rectDummy(0,0,200,600); //rectDummy.SetRectEmpty(); CTreeCtrl m_wndClassView; const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; if (!m_wndClassV

我的应用程序如下所示:

CRect rectDummy(0,0,200,600);
//rectDummy.SetRectEmpty();

CTreeCtrl m_wndClassView;

const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

if (!m_wndClassView.Create(dwViewStyle, rectDummy, &m_wndView, 2))
{
    TRACE0("Failed to create Class View\n");
    return -1;      // fail to create
}


HTREEITEM hRoot = m_wndClassView.InsertItem(_T("System Summary"), 0, 0);
m_wndClassView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);

HTREEITEM hClass = m_wndClassView.InsertItem(_T("Hardwre Resources"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Components"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Software Enviroment"), 1, 1, hRoot);

我希望它看起来像这样:

CRect rectDummy(0,0,200,600);
//rectDummy.SetRectEmpty();

CTreeCtrl m_wndClassView;

const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

if (!m_wndClassView.Create(dwViewStyle, rectDummy, &m_wndView, 2))
{
    TRACE0("Failed to create Class View\n");
    return -1;      // fail to create
}


HTREEITEM hRoot = m_wndClassView.InsertItem(_T("System Summary"), 0, 0);
m_wndClassView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);

HTREEITEM hClass = m_wndClassView.InsertItem(_T("Hardwre Resources"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Components"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Software Enviroment"), 1, 1, hRoot);

我正在使用的代码:

CRect rectDummy(0,0,200,600);
//rectDummy.SetRectEmpty();

CTreeCtrl m_wndClassView;

const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

if (!m_wndClassView.Create(dwViewStyle, rectDummy, &m_wndView, 2))
{
    TRACE0("Failed to create Class View\n");
    return -1;      // fail to create
}


HTREEITEM hRoot = m_wndClassView.InsertItem(_T("System Summary"), 0, 0);
m_wndClassView.SetItemState(hRoot, TVIS_BOLD, TVIS_BOLD);

HTREEITEM hClass = m_wndClassView.InsertItem(_T("Hardwre Resources"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Components"), 1, 1, hRoot);
hClass = m_wndClassView.InsertItem(_T("Software Enviroment"), 1, 1, hRoot);
如果可能的话,我更喜欢使用MFC/C++的解决方案,并且不使用第三方库


要获得这种外观,您需要几样东西:

  • 确保应用程序清单指定comctl32 v6
  • 创建树视图后,添加对
    SetWindowTheme(hTreeView,L“explorer”,NULL)
    的调用。此处
    hTreeView
    是树状视图的窗口句柄

  • uxtheme.lib
    库添加依赖项,包括
    头,在创建控件后调用函数:

    SetWindowTheme(hYourTreeviewHandle, L"Explorer", NULL);
    
    这将使您的treeview控件具有Windows资源管理器的外观。由于您需要提供自己的图像列表,还需要利用宏将图像列表附加到treeview,因此需要更多的操作:

    TreeView_SetImageList(hYourTreeviewHandle, hYourImagesHandle, TVSIL_NORMAL);
    

    。您好,您能告诉我如何删除点以及“元素之间的点线”@Karim从您的
    常量DWORD dwViewStyle=…
    代码中删除
    TVS\u线
    TVS\u线根
    窗口样式吗。有关treeview样式的更多信息,请访问。