TreeView icons have a black background.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am making a Tree View Dialog which allows you to browse a file system remotely, I am currently trying to just get things up and running on a local machine, I have a dialog up and running and it works nicely, to get the icons for the tree view I am using
the following SetIcon() function:<br/>
<br/>
<pre class="prettyprint BOOL
SetIcon (
HWND hWndTV,
LPSHELLFOLDER pFolder,
LPITEMIDLIST pidl )
{
TCHAR iconName[MAX_PATH];
IExtractIcon *pExtractor = NULL;
HICON hIconSmall;
HIMAGELIST hIml;
int iconIndex = 0;
UINT flag = 0;
HRESULT hr;


hr = pFolder->lpVtbl->GetUIObjectOf ( pFolder, NULL, 1, (LPCITEMIDLIST*)&pidl, &IID_IExtractIcon, NULL, (LPVOID*)&pExtractor );
if ( hr == S_OK )
{
hr = pExtractor->lpVtbl->GetIconLocation ( pExtractor, GIL_FORSHELL, iconName, MAX_PATH, &iconIndex, &flag );
if ( hr == S_OK )
{
hr = pExtractor->lpVtbl->Extract ( pExtractor, iconName, iconIndex, NULL, &hIconSmall, 0x00100020 );
if ( hr == S_OK )
{
hIml = TreeView_GetImageList ( hWndTV, TVSIL_NORMAL );
g_nIcon = ImageList_AddIcon ( hIml, hIconSmall );
DestroyIcon ( hIconSmall );
return TRUE;
}
}
}
return FALSE;
}[/code]
This feeds into an image list which is initialized as follows:<br/>
<br/>
<pre class="prettyprint BOOL
InitTreeViewImageLists(
HWND hwndTV)
{
HIMAGELIST himl; // handle to image list
HBITMAP hbmp; // handle to bitmap

// Create the image list.
if ((himl = ImageList_Create(16,
16,
ILC_COLOR32,
100, 0)) == NULL)
return FALSE;

// Add the open file, closed file, and document bitmaps.
hbmp = LoadBitmap(g_nhInst, MAKEINTRESOURCE(IDB_FOLDER));
g_nIcon = ImageList_Add(himl, hbmp, (HBITMAP)NULL);
DeleteObject(hbmp);

// Fail if not all of the images were added.
if (ImageList_GetImageCount(himl) < 1)
return FALSE;

// Associate the image list with the tree-view control.
TreeView_SetImageList( hwndTV, himl, TVSIL_NORMAL);

return TRUE;
} [/code]
The SetIcon() function is called just before I add something to the tree, this means the global g_nIcon is the index of the last extracted icon and the relevant part of the AddItemToTree() function is as follows:<br/>
<br/>
<pre class="prettyprint tvi.iImage = g_nIcon;
tvi.iSelectedImage = g_nIcon;[/code]
My issue is that there are clearly transparent parts of these icons, which when displayed in the dialog appear black, like a black background. Is there any way to change this, to either handle transparency correctly or just make it paint the transparent
parts white instead of black?<br/>
<br/>
<br/>

View the full article
 
Back
Top