CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Location
    California, USA
    Posts
    9

    ::ExtractIconEx()

    Hi,

    Currently I am extracting an icon from an excutable and adding that icon to a toolbar button within my application. The following code shows how I accomplish this:

    void CZManagerApp::LoadUserDefinedToolBarIcons()
    {
    CZString strTool;
    HICON hIconSmall;
    ICONINFO IconInfo;
    TBBUTTON tbButton;


    m_uStartID = m_uCommandID;

    strTool = "some executable file.exe";

    ::ExtractIconEx((LPCTSTR)strTool, 0, NULL, &hIconSmall, 1);

    ::GetIconInfo(hIconSmall, &IconInfo);

    // Where m_TBControl is of type "CToolBarCtrl"
    tbButton.iBitmap = m_TbControl.AddBitmap(1, CBitmap::FromHandle(IconInfo.hbmColor));

    tbButton.idCommand = m_uCommandID;
    tbButton.fsState = TBSTATE_ENABLED;
    tbButton.fsStyle = TBSTYLE_BUTTON;
    tbButton.dwData = 0;
    tbButton.iString = 0;

    m_TbControl.AddButtons(1, &tbb);

    DestroyIcon(hIconSmall);

    m_uCommandID++;
    }

    This works great except for when the icon is transparent in areas then I get the transparent areas showing up as black. Does anyone know what I'm missing?

    Dan


  2. #2
    Join Date
    May 1999
    Posts
    44

    Re: ::ExtractIconEx()

    The ICONINFO structure contains two bitmaps. One is the hbmColor, and the other is the hbmMask. What you'd need to do is to create a CBitmap that uses the hbmMask to map your desired background color. One way of doing this would be to create a DC via GetDC(NULL), selecting a compatible bitmap into it, fill the bitmap with your toolbar background color, then :rawIcon(... hIconSmall ..) into it. That way, you let DrawIcon do the masking and stuff for you. Then you add that bitmap to your toolbar control in the same manner as you do now.

    Regards,
    /Robert


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