开发者

How to add image in CTreeCtrl list in MFC

开发者 https://www.devze.com 2023-03-04 20:20 出处:网络
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 ,

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:-

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...


Now you just need to set the image for the newly created branch:

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.

Instead of ILC_COLOR32 use ILC_COLOR.

And instead of RGB(0,0,0) use (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.

0

精彩评论

暂无评论...
验证码 换一张
取 消