/* Sets a tabs icon. Normally, this icon is the folders icon, however if the tab is locked, the icon will be a lock. */ void Explorerplusplus::SetTabIcon(int iIndex,int iTabId,LPITEMIDLIST pidlDirectory) { TCITEM tcItem; SHFILEINFO shfi; ICONINFO IconInfo; int iImage; int iRemoveImage; /* If the tab is locked, use a lock icon. */ if(m_TabInfo[iTabId].bAddressLocked || m_TabInfo[iTabId].bLocked) { iImage = TAB_ICON_LOCK_INDEX; } else { SHGetFileInfo((LPCTSTR)pidlDirectory,0,&shfi,sizeof(shfi), SHGFI_PIDL|SHGFI_ICON|SHGFI_SMALLICON); /* TODO: The proxy icon may also be the lock icon, if the tab is locked. */ SetTabProxyIcon(iTabId,shfi.hIcon); GetIconInfo(shfi.hIcon,&IconInfo); iImage = ImageList_Add(TabCtrl_GetImageList(m_hTabCtrl), IconInfo.hbmColor,IconInfo.hbmMask); DeleteObject(IconInfo.hbmColor); DeleteObject(IconInfo.hbmMask); DestroyIcon(shfi.hIcon); } /* Get the index of the current image. This image will be removed after the new image is set. */ tcItem.mask = TCIF_IMAGE; TabCtrl_GetItem(m_hTabCtrl,iIndex,&tcItem); iRemoveImage = tcItem.iImage; /* Set the new image. */ tcItem.mask = TCIF_IMAGE; tcItem.iImage = iImage; TabCtrl_SetItem(m_hTabCtrl,iIndex,&tcItem); if(iRemoveImage != TAB_ICON_LOCK_INDEX) { /* Remove the old image. */ TabCtrl_RemoveImage(m_hTabCtrl,iRemoveImage); } }
bool RemoveTab(HWND TabWindow, int Index) { assert(IsWindow(TabWindow)); assert(Index >= 0); assert(Index < TabCtrl_GetItemCount(TabWindow)); TC_ITEM TabData; TabData.mask = TCIF_IMAGE | TCIF_PARAM; if(TabCtrl_GetItem(TabWindow, Index, &TabData)) { int CurIndex = TabCtrl_GetCurSel(TabWindow); assert(CurIndex >= -1); if(CurIndex != -1 && TabCtrl_DeleteItem(TabWindow, Index)) { if(TabData.iImage != -1) TabCtrl_RemoveImage(TabWindow, TabData.iImage); int Count = TabCtrl_GetItemCount(TabWindow); assert(Count >= 0); if(Count == 0) // We just removed the last one, do some addition cleanup { ShowWindow(reinterpret_cast<HWND>(TabData.lParam), SW_HIDE); HIMAGELIST ImageList = TabCtrl_GetImageList(TabWindow); if(ImageList) { ImageList_Destroy(ImageList); TabCtrl_SetImageList(TabWindow, NULL); } RemoveProp(TabWindow, PropName); } else if(Index == CurIndex) // We're deleting the currently visible tab { if(Index == Count) // Last tab Index--; TabToFront(TabWindow, Index); } SetTabThemeTexture(reinterpret_cast<HWND>(TabData.lParam), false); return true; } } return false; }
bool SetTabIcon(HWND TabWindow, int Index, HICON Icon) { assert(IsWindow(TabWindow)); assert(Index >= 0); assert(Index < TabCtrl_GetItemCount(TabWindow)); HIMAGELIST ImageList = TabCtrl_GetImageList(TabWindow); if(!ImageList) // Create a new image list { ImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1); TabCtrl_SetImageList(TabWindow, ImageList); } TC_ITEM TabData; TabData.mask = TCIF_IMAGE; if(TabCtrl_GetItem(TabWindow, Index, &TabData)) { if(Icon) // Add icon { if(TabData.iImage == -1) // There is no icon yet TabData.iImage = ImageList_AddIcon(ImageList, Icon); else TabData.iImage = ImageList_ReplaceIcon(ImageList, TabData.iImage, Icon); } else // Remove icon { if(TabData.iImage != -1) // Skip if there is no icon { TabCtrl_RemoveImage(TabWindow, TabData.iImage); TabData.iImage = -1; } } return TabCtrl_SetItem(TabWindow, Index, &TabData); } return false; }