From: Guru on

I am using icons for my toolbar, however each of the icons has a white (or light grey) background which is ugly. Any help is appreciated.

if (!myBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

myBar.LoadToolBar(IDR_TOOLBAR1);

list1.Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 2);

list1.SetBkColor(RGB(255,255,255));

list1.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
list1.Add(AfxGetApp()->LoadIcon(IDI_ICON2));

myBar.SendMessage(TB_SETIMAGELIST, 0 , LPARAM (list1.m_hImageList));

myBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&myBar);



justmehere wrote:

Re: Coding help for loading custom icons into toolbar
18-Mar-09

Thanks for the help all is working now. Appreciate the help.

Previous Posts In This Thread:

On Sunday, March 15, 2009 7:49 PM
David Lowndes wrote:

What aspect of it doesn't work?
What aspect of it doesn't work?


You should probably use LoadImage rather than LoadIcon.

Note the MSDN documentation says:

"LoadIcon can only load an icon whose size conforms to the SM_CXICON
and SM_CYICON system metric values. Use the LoadImage function to load
icons of other sizes."

Dave

On Monday, March 16, 2009 7:52 AM
David Lowndes wrote:

Re: Coding help for loading custom icons into toolbar
Something like this:

HICON hU = LoadImage( g_hInstance, MAKEINTRESOURCE( IDI_UP ),
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR );


Dave

On Monday, March 16, 2009 1:25 PM
David Lowndes wrote:

You need to break your code down a bit - are the icon images gettingloaded
You need to break your code down a bit - are the icon images getting
loaded successfully?

Dave

On Wednesday, March 18, 2009 12:22 AM
justmehere wrote:

Coding help for loading custom icons into toolbar
I am using Visual C++ 6.0 and MFC in a Dialog based project. All I
want to is to be able to load custom icons which are all (3 of them)
imported into the resource section of the project onto a Toolbar which
has been created. Right now the Toolbar loads the default bitmap which
is also located in the resource portion of the project. One further
note is that I wish to load custom icons which are 72x72 pixels in
dimensions. Another words I want large buttons showing up on the
Toolbar. All the code is called from the OnInitDialog() function. My
code unfortunately does not work. Any help or suggestions would be
greatly appreciated. Many thanks.

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE |
CBRS_TOP
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{

TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

list.Create(72, 72, ILC_COLOR32|ILC_MASK, 3, 0);
list.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
list.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
list.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
//list.Add(&bmp, RGB(192,192,192)); //192,192,192 is the mask color

m_wndToolBar.GetToolBarCtrl().SetImageList(&list);

On Wednesday, March 18, 2009 12:22 AM
justmehere wrote:

Re: Coding help for loading custom icons into toolbar
Thanks for the reply. The buttons do not display at all on the main
window. Can you give me an example of the useage of the LoadImage
function?

On Wednesday, March 18, 2009 12:22 AM
justmehere wrote:

Also if I try the following code below all three buttons with theirrespective
Also if I try the following code below all three buttons with their
respective image displays and all butons are enabled so you can click
on them but all three buttons are cut off another words they are half
their height. Any ideas ? Thanks for the help.

CWinApp* pApp = AfxGetApp();
mImageList.Create(72, 72, ILC_COLOR32 | ILC_MASK, 3,3);
mImageList.Add(pApp->LoadIcon(IDI_ICON1));
mImageList.Add(pApp->LoadIcon(IDI_ICON2));
mImageList.Add(pApp->LoadIcon(IDI_ICON2));
m_ToolBar.Create(WS_CHILD|WS_VISIBLE|WS_BORDER, CRect(0,0,0,0), this,
0);

m_ToolBar.SetImageList(&mImageList);
TBBUTTON tb;

tb.iBitmap = 0;
tb.iString = NULL;
tb.fsState = TBSTATE_ENABLED ;
tb.fsStyle = TBSTYLE_BUTTON;
tb.idCommand = ID_BUTTON32785;

m_ToolBar.AddButtons(1, &tb);
tb.iBitmap = 1;
tb.idCommand = ID_BUTTON32786;
m_ToolBar.AddButtons(1, &tb);
tb.iBitmap = 2;
tb.idCommand = ID_BUTTON32787;
m_ToolBar.AddButtons(1, &tb);

On Wednesday, March 18, 2009 12:22 AM
justmehere wrote:

Re: Coding help for loading custom icons into toolbar
On Mar 16, 3:52=A0am, David Lowndes <Dav...(a)example.invalid> wrote:
_UP ),
ULTCOLOR );

Thanks Dave I gave this funcion a try but I still could not get it to
work. I believe instead of using the LoadIcon function I you have
suggested replacing it with the LoadIage function. But still I get no
buttons displayed on the Toolbar. Appreciate the help.

On Wednesday, March 18, 2009 12:22 AM
justmehere wrote:

Re: Coding help for loading custom icons into toolbar
Thanks for the help all is working now. Appreciate the help.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Build a Selected Text Favorites Utility for your Web Site
http://www.eggheadcafe.com/tutorials/aspnet/d72a2557-4ffd-4d29-bf1c-86feb39cae83/build-a-selected-text-fav.aspx
From: Eddie Paz on
Since you're loading icons into the CImageList, you don't need to set the
background color or the ILC_MASK. CImageList generally manages the
transparency which in your case it's now (the ugly background). Usually for
a toolbar, you load images as a bitmap with a color like magenta as the mask
color (background), and then set the mask so CImageList can replace the mask
color (not draw it). Hope that helps.

Eddie.

"Guru Prasath" wrote in message news:201022318163lakshmanguru(a)yahoo.com...
>
> I am using icons for my toolbar, however each of the icons has a white (or
> light grey) background which is ugly. Any help is appreciated.
>
> if (!myBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD |
> WS_VISIBLE | CBRS_TOP
> | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
> {
> TRACE0("Failed to create toolbar\n");
> return -1; // fail to create
> }
>
> myBar.LoadToolBar(IDR_TOOLBAR1);
>
> list1.Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 2);
>
> list1.SetBkColor(RGB(255,255,255));
>
> list1.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
> list1.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
>
> myBar.SendMessage(TB_SETIMAGELIST, 0 , LPARAM (list1.m_hImageList));