[英]How to add image in CTreeCtrl list in MFC
I am trying to add Image before the text in CTreeList control but it is not coming up, But what i observed is the the node name is started after some space , like it is leaving the space for bitmap , but image is not showing up.. here is the code snap:-我试图在 CTreeList 控件中的文本之前添加 Image 但它没有出现,但我观察到的是节点名称在一些空格之后开始,就像它为位图留下空间一样,但图像没有显示。 . 这是代码快照:-
CImageList m_ImageList;
CBitmap m_Bitmap1;
m_ImageList.Create(16,16,ILC_COLOR32,1,1);
m_Bitmap1.LoadBitmap(IDB_BITMAP1);
m_ImageList.Add(&m_Bitmap1, RGB(0,0,0));
TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |
TVS_TRACKSELECT,
CRect(10, 10, 200, 240), this, 0x1221);
TreeSoft->SetImageList(&m_ImageList, TVSIL_NORMAL);
hTree = TreeSoft->InsertItem( L"Software Production",0,0, TVI_ROOT);
hCompany = TreeSoft->InsertItem(L"Microsoft",0,0, hTree);
Pls tell me what i am missing here...请告诉我我在这里缺少什么...
现在你只需要为新创建的分支设置图像:
TreeSoft->SetItemImage(hTree , 0, 0); // I think it starts from 0 (if it does not show try 1)
Just for testing purposes.仅用于测试目的。 Create an icon with 16-bit color palette.
创建一个带有 16 位调色板的图标。
Instead of ILC_COLOR32 use ILC_COLOR.使用 ILC_COLOR 代替 ILC_COLOR32。
And instead of RGB(0,0,0) use (COLORREF)0xFFFFFF而不是 RGB(0,0,0) 使用 (COLORREF)0xFFFFFF
I have exact the same code except the smaller color palette and it works.除了较小的调色板之外,我有完全相同的代码并且它可以工作。
If this works you can try with the bigger palette.如果这有效,您可以尝试使用更大的调色板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.