с++ Microsoft MFC 树视图图标
С++ Microsoft MFC TreeView Icons
我通过一篇博客文章编写了 TreeView 控件的代码。我正在尝试向列表项添加图标。但是图标不会呈现。我有下一个代码:
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
// TODO: Add items by GetTreeCtrl().
HICON hi = NULL;
hi = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_ICON1));
if (hi != NULL)
{
MessageBox(NULL, L"resource1");
}
else MessageBox(NULL, L"Not resource1");
HICON lo = NULL;
lo = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_ICON2));
if (lo != NULL)
{
MessageBox(NULL, L"resource2");
}
else MessageBox(NULL, L"Not resource2");
CImageList m_tree_imglist;
CTreeCtrl & tc = CTreeView::GetTreeCtrl();
m_tree_imglist.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 2);
m_tree_imglist.Add(hi);
m_tree_imglist.Add(lo);
tc.SetImageList(&m_tree_imglist, TVSIL_NORMAL);
HTREEITEM hItem;
hItem = tc.InsertItem(L"Fonts", 0, 0, TVI_ROOT);
tc.InsertItem(L"Arial", 0, 0, hItem);
tc.InsertItem(L"Times", 0, 0, hItem);
tc.Expand(hItem, TVE_EXPAND);
}
图标已添加到资源的文件中。我有错误吗?我有带有下一个文本的消息框:"资源 1"、"资源 2"。
m_tree_imglist
在堆栈上声明,此映像列表在 OnInitialUpdate
退出后被销毁,因此CTreeCtrl
不再具有映像列表。
图像列表应声明为类成员,以便只要CTreeCtrl
需要它,它就保持有效。请注意,m_
前缀通常在 MFC 中用于指示"类成员"。
class CLeftView : public CTreeView
{
CImageList m_tree_imglist;
...
};
void CLeftView::OnInitialUpdate()
{
...
//CImageList m_tree_imglist; <- remove
tc.SetImageList(&m_tree_imglist, TVSIL_NORMAL);
}
相关文章:
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 视图中的参数推导失败:take_while
- 如何维护资源管理器项目视图中当前可见的项目列表
- 在另一个类视图中添加最多2个图表的正确方法是什么
- OpenVR:向视图方向移动
- 使用 WIN32 API (C/C++) 对特定树视图项进行着色
- 将所选值(通过视图)从 boost::multi_array 复制到另一个数组 (C++)
- 如何在不使用滚动条的情况下使视图更改
- 列表视图更改选择颜色
- 如何为 C++ Visual Studio 2019 指定应用程序图标?
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 从 wxWidgets 中的.DLL加载图标
- 如何修复加载图标()函数不显示图标?
- 在 Qml 中从 QSqlTableModel 中删除单行时视图不一致
- QT Framewrok 和 Visual Studio - 图标冲突
- 如何在 c++ 中将图标放在按钮上?
- Visual Studio 2015资源视图和资源编译器使用不同的方法在项目目录中查找图标文件.如何修复
- с++ Microsoft MFC 树视图图标
- QtQuick:更改树视图中的展开图标
- 列表视图-资源管理器如何在小图标视图中获得相同大小的所有项目