?
Solved

transparent icons have black background

Posted on 2004-10-14
1
Medium Priority
?
978 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 500 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

743 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