CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2005
    Posts
    1,828

    Transparent ICON Background

    I have developed an Internet Explorer Searchbar using ATL COM with the help of this tutorial

    http://www.codeproject.com/KB/shell/...rtutorial.aspx

    There is one small problem. The background of the icons is black instead of transparent. This is the code for attaching ICONS with the toolbar

    Code:
    LRESULT CMFToolbar::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    	// buttons with images and text
    	SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_MIXEDBUTTONS);
    	// Sets the size of the TBBUTTON structure.
    	SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
    	// Set the maximum number of text rows and bitmap size.
    	SendMessage(m_hWnd, TB_SETMAXTEXTROWS, 1, 0L);
    
    	SendMessage(m_hWnd, TB_SETROWS, MAKEWPARAM(1, 0), (LPARAM)NULL);
    
    	SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
    
    	
    	// add our button's caption to the toolbar window
    	TCHAR* pCaption = _T("Members");
    	int iIndex = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption);	
    
    	TCHAR* pCaption1 = _T("Forums");
    	int iIndex1 = ::SendMessage(m_hWnd, TB_ADDSTRING, 0,(LPARAM)pCaption1);
    
    
    	// load our button's icon and create the image list to house it.
    	HICON hMotley = (HICON)LoadImage(_Module.m_hInst, MAKEINTRESOURCE(IDI_ICON1_SEARCH),
    			IMAGE_ICON, 16, 16, LR_SHARED | LR_DEFAULTCOLOR); 
    
    		//LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_ICON1_SEARCH));
    
    	m_hImageList = ImageList_Create(16,16, ILC_COLOR16 | ILC_MASK, 1, 0);
    	int iImageIndex = ImageList_AddIcon(m_hImageList, hMotley);
    
    	HICON hForums = LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_ICON_FORUMS));
    	int iImageIndex1 = ImageList_AddIcon(m_hImageList, hForums);
    
    
    	DestroyIcon(hMotley);
    	DestroyIcon(hForums);
    
    	// Set the toolbar's image
    	::SendMessage(m_hWnd, TB_SETIMAGELIST, 0, (LPARAM)m_hImageList);
    
    	// add the button for the toolbar to the window
    	TBBUTTON Button;
    	ZeroMemory((void*)&Button, sizeof(TBBUTTON));
    	Button.idCommand = IDM_GETQUOTE;
    	Button.fsState = TBSTATE_ENABLED;
    	Button.fsStyle = TBSTYLE_BUTTON | TBSTYLE_AUTOSIZE | TBSTYLE_DROPDOWN;
    	Button.dwData = 0;
    	Button.iString = NULL;
    	Button.iBitmap = iImageIndex;
    	::SendMessage(m_hWnd, TB_INSERTBUTTON, 0, (LPARAM)&Button);	
    
    	TBBUTTON Button1;
    	ZeroMemory((void*)&Button1, sizeof(TBBUTTON));
    	Button1.idCommand = IDM_FORUM;
    	Button1.fsState = TBSTATE_ENABLED;
    	Button1.fsStyle = BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT | TBSTYLE_TRANSPARENT/*| BTNS_DROPDOWN*/;
    	Button1.dwData = 0;
    	Button1.iString = iIndex1;
    	Button1.iBitmap = iImageIndex1;
    	::SendMessage(m_hWnd, TB_INSERTBUTTON, 1, (LPARAM)&Button1);
    
    
    	m_hMenu = CreatePopupMenu();
    	AppendMenu (m_hMenu, MF_ENABLED | MF_STRING, 0, _T("Forums"));
    	AppendMenu (m_hMenu, MF_ENABLED | MF_STRING, 1, _T("Sessions"));
    	AppendMenu (m_hMenu, MF_ENABLED | MF_STRING, 2, _T("Application"));
    	AppendMenu (m_hMenu, MF_ENABLED | MF_STRING, 3, _T("Cache"));
    	//CheckMenuItem (m_hMenu, 0, MF_CHECKED | MF_BYCOMMAND);
    
    	// create our EditQuote window and set the font.
    	RECT rect = {0,0,0,0};
    	m_EditWnd.Create(m_hWnd, rect, NULL, WS_CHILD|WS_VISIBLE, WS_EX_CLIENTEDGE);
    	m_EditWnd.SetFont(static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT)));
    	return 0;
    }

    So how can I make those ICONS with transparent background??

  2. #2
    Join Date
    Apr 2010
    Location
    Dayton, OH
    Posts
    16

    Re: Transparent ICON Background

    I believe you have to save your Icon with the transparent color as the background and Windows will take care of the rest when displaying the icon. There should be an option for doing this in whatever image program you used to create your icon.

    It will either be something along the lines of "Set Transparent Color" to let you choose a color to use to represent transparency, or it'll be one of the selectable colors already available to you, depending on the program.

  3. #3
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Transparent ICON Background

    Yes, those icons have transparent background. When i use the same icons for simple IE buttons using registry, its background becomes transparent. But in case of this toolbar the background is automatically becoming black

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: Transparent ICON Background

    m_hImageList = ImageList_Create(16,16, ILC_COLOR16 | ILC_MASK, 1, 0);
    Maybe you could try without the ILC_MASK or the ILC_COLOR16 flag or with some other values.
    Last edited by olivthill2; April 12th, 2010 at 02:54 AM.

  5. #5
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Transparent ICON Background

    OK. Here I discovered a wiered problem. I transferred my code into different PC. It had a different platorm SDK

    Code:
    C:\Program Files\Microsoft Platform SDK for Windows XP SP2\Include
    In that toolbar was displaying transparent background for those ICONS instead of black. Can somone give me some hint?

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Transparent ICON Background

    Did you try olivthill2's suggestion? Try: ILC_COLOR32|ILC_MASK

  7. #7
    Join Date
    Apr 2005
    Posts
    1,828

    Re: Transparent ICON Background

    Yes. it somehow worked. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured