Solved

transparent icons have black background

Posted on 2004-10-14
1
903 Views
Last Modified: 2013-11-20
Hi Experts,

I'm creating a toolbar control with custom icons.  The problem I have is that the icons have a black background when I want transparency instead.  

The icon I'm using:
The icon was created using adobe illustrator plus axialis icon workshop.  The icon is available in many different sizes/color depths, and the colors look ok except for the black-instead-of-transparent background.  When I use the icon on my WinXP desktop, it looks fine with proper transparency.  You can see my icon file at http://amis.sf.net/temp/arrow.ico.

Dev environment:
MSVC 6 running on WinXP
Project is an MFC exe, SDI, with CFrameWnd derived main window.  The code below is executed in the window's OnCreate function.

Here are the steps I've taken:


///////////////begin code///////////////////////////////////////////////
//the path to the icon file
CString szIconFile("c:\\docs\\arrow.ico");

//the image list (i've also tried the ILC_COLOR8 flag instead)
m_tb1_images.Create(24,24,ILC_COLOR24,4,4);

//create an icon resource
HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDR_ICON),RT_GROUP_ICON);

//load the icon from file
HICON hIcon = (HICON)LoadImage(hInst,szIconFile,IMAGE_ICON,24,24,
            LR_LOADFROMFILE);

//add the icon to the image list
m_tb1_images.Add(hIcon);

//create the toolbar (it's a CToolBarCtrl object)
m_tb1.Create(WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, rect, this, ID_TOOLBAR);

//set the image list
m_tb1.SetImageList(&m_tb1_images);

//add a string to the toolbar
m_tb1.AddString(IDS_OPEN);


//button structure(s)
TBBUTTON buttons[1];

buttons[0].iBitmap = 0;
buttons[0].idCommand = ID_CMD_OPEN;
buttons[0].fsState = TBSTATE_ENABLED;
buttons[0].fsStyle =  TBSTYLE_BUTTON;
buttons[0].iString = 0;

//add a button to the toolbar
m_tb1.AddButtons(1, &buttons[0]);

//auto size the toolbar
m_tb1.AutoSize();

///////////////end code///////////////////////////////////////////////

Thanks
Marisa
0
Comment
Question by:marisademeglio
1 Comment
 
LVL 3

Accepted Solution

by:
_mb_ earned 125 total points
ID: 12316408
It should work with the ILC_MASK Flag for the image list:
m_tb1_images.Create(24, 24, ILC_COLOR24 | ILC_MASK, 4, 4);
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 34
method notes when mouse over in eclipse 5 87
abstract class with all non abstract mentods 6 76
Problem to event 3 98
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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