Solved

transparent icons have black background

Posted on 2004-10-14
1
876 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

705 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

19 Experts available now in Live!

Get 1:1 Help Now