Solved

Icon background when using ExtractIcon

Posted on 2001-07-26
3
444 Views
Last Modified: 2013-11-20
I'm using Visual C++ 6.0 on Windows98.  I'm writing an application that has a tree view and a list view, much the same as Windows Explorer.  I'm trying to add a basic computer icon to the tree control in the tree view.  I've created a few of my own icons and added them through the resource editor.  They all appear fine in the tree control.  I wanted to use a standard icon for a computer and chose to use the shell32.dll.

In the code, OnInitialUpdate I create a CImageList with the following construction:

m_ImageList.Create(20, 20, ILC_COLOR32, 16, 4);

I then load my personal icons:

HICON hIcon;
int nMyIconIndex;

hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_MY_ICON));
nMyIconIndex = m_ImageList.Add(hIcon);

like I said, this works fine and the icons appear on the tree control.  

I then try to do the standard icon this way:

hIcon = ::ExtractIcon(AfxGetResourceHandle(), "c:\\windows\\system\\shell32.dll", 15);
nLoadedIcon = m_ImageList.Add(hIcon);

When I display the icon in the tree control, the icon is visible, however the background of the icon is black.  Since the tree view background is white, it is easy to see the black background of the icon.  I've tried to use the m_ImageList.SetBkColor(CLR_NONE) and m_ImageList.SetBkColor(RGB(0,0,0)) and neither one yielded any difference.

How can I get rid of that black background on the standard icon that I load via ExtractIcon.

Or is there somewhere I could get a .ico file that corresponds to the standard icons in windows?  Then I could just add the .ico file right into the resource editor.  

Any help would be greatly appreciated.


0
Comment
Question by:jstephe1
3 Comments
 
LVL 12

Accepted Solution

by:
migel earned 100 total points
ID: 6322956
Hi!
try use this:
m_ImageList.Create(20, 20, ILC_COLOR32|ILC_MASK, 16, 4);
0
 
LVL 6

Expert Comment

by:MichaelS
ID: 6322973
>Or is there somewhere I could get a .ico file that corresponds to the standard icons in windows?  Then
I could just add the .ico file right into the resource editor.  

I think you have to take a look at code like that:

HIMAGELIST  himl;
SHFILEINFO  sfi;

himl = (HIMAGELIST)SHGetFileInfo(TEXT("C:\\"), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX);
0
 

Author Comment

by:jstephe1
ID: 6323078
Thanks a lot.  Works perfect.  And thanks for getting back to me so soon!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 89
MaxSpan challenge 9 80
fix34  challenge 9 105
changeXy challenge 13 67
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now