How to generate a new icon at runtime for MFC tree control
-
I know how to change an icon, I was just wondering if anybody knows how to generate new icons at runtime, or ideally how to create a new icon identical to the previous but with different colours? Alternatively, is it possible to change display colours of an icon without creating a new one? When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
-
I know how to change an icon, I was just wondering if anybody knows how to generate new icons at runtime, or ideally how to create a new icon identical to the previous but with different colours? Alternatively, is it possible to change display colours of an icon without creating a new one? When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
You can create a bitmap using the
CreateBitmap
API. Then you can use GDI to draw to it. Then you add it to the image list of the tree control using theImageList_Add
function. MFC has wrappers for there APIs. Steve -
I know how to change an icon, I was just wondering if anybody knows how to generate new icons at runtime, or ideally how to create a new icon identical to the previous but with different colours? Alternatively, is it possible to change display colours of an icon without creating a new one? When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
CImageList *m_ImageTree; TV_INSERTSTRUCT TreeItem; HTREEITEM hTreeItem; CBitmap bit; m_ImageTree = new CImageList(); m_ImageTree->Create(15,15, ILC_COLORDDB,0,0); TreeItem.hParent = TVI_ROOT; TreeItem.hInsertAfter = TVI_LAST; TreeItem.item.mask = TVIF_TEXT | TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE; TreeItem.item.pszText = _T("TEST"); TreeItem.item.lParam = 0; TreeItem.item.iImage=0; TreeItem.item.iSelectedImage=0; hTreeItem = m_Tree1.InsertItem(&TreeItem); bit.LoadBitmap(IDB_BITMAP1); m_ImageTree->Add(&bit,RGB(255,0,255)); m_Tree1.SetImageList(m_ImageTree, LVSIL_NORMAL);
-
I know how to change an icon, I was just wondering if anybody knows how to generate new icons at runtime, or ideally how to create a new icon identical to the previous but with different colours? Alternatively, is it possible to change display colours of an icon without creating a new one? When I die I'd like to go peacefully in my sleep like my father, not screaming in terror like his passengers!!!
and you can replace HBITMAP hBmp = (HBITMAP)LoadImage(NULL,"c:\\a.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); bit.Attach(hBmp); instead bit.LoadBitmap(IDB_BITMAP1);