Solved

transparent icons have black background

Posted on 2004-10-14
1
948 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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