[TreeCtrl]CTreeLis於Item前塞入圖示

這邊找到的方法是使用CImageList來實作。要注意的是,這邊宣告的CImageList要為Data member,否則會無法顯示圖示。

這邊使用的Icon為BitMap,建立的圖形長度為16bits。
因此在CImageList::Create()要輸入的cx值為16。

建立好CImageList後,再把把他透過CTreeList::SetItemImage()塞給所要使用的CTreeList即可。

程式碼如下:
header
 ....  
 CImageList m_cImageList;  
 ....  

CPP:
     if ( !m_cImageList.Create(IDB_BMP_ICON, 16, 2, RGB(0, 0, 0)) ) {  
         CDSMsgShower::ShowMsgByErrorBox(this->m_hWnd, "ACCERT", MB_OK, "Fail to create image list."); };  
   
     this->m_treEnvItems.SetImageList(&m_cImageList, TVSIL_NORMAL);  
   
     ....  
     this->m_treEnvItems.SetItemImage(hEnvItemsTree, 0, 1);  

如圖形無法顯示,有可能是輸入的bitmap長度有錯。

1 comment:

  1. Sorry for that I may not be able to read your comment. Would you mind to comment again in English? thanks

    ReplyDelete

Build docker image from multiple build contexts

Build docker image from multiple build contexts ...