Print Page | Close Window

Get HICON from XTPImageManager

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=16605
Printed Date: 16 July 2025 at 2:15pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Get HICON from XTPImageManager
Posted By: jimmy
Subject: Get HICON from XTPImageManager
Date Posted: 16 April 2010 at 7:01am
Hello,

have some trouble after change from V11.1.3 to V14.0.0Beta.

i add a Toolbar to XTPImageManager.
than i will get a HICON, but it return NULL.

add this lines
CXTPImageManagerIcon* pIcon = pCommandBars->GetImageManager()->GetImage(ID_COLOR_FORE);
HICON hIcon1 = pIcon->GetIcon();

after
line:     pCommandBars->GetImageManager()->SetIcons(IDR_TOOLBAR_COLOR);
in CommandBarControls Sample (MainFrm.cpp).

  hIcon1 is NULL.

Any solution to retrieve HICON ?

Thanks
   Jimmy






Replies:
Posted By: znakeeye
Date Posted: 23 April 2010 at 6:11am
Later versions store icons as one single image to decrease GDI resource usage. Try something like this:
 
BOOL IconFromPNG(HINSTANCE hInstance, UINT nResourceID, CXTPImageManagerIconHandle &hIconHandle)
{
    hIconHandle.Clear();

    BOOL bAlphaBitmap = FALSE;
    HBITMAP hBitmap = CXTPImageManagerIcon::LoadBitmapFromResource(hInstance, MAKEINTRESOURCE(nResourceID), &bAlphaBitmap);
    if (hBitmap)
    {
        if (bAlphaBitmap)
        {
            hIconHandle = hBitmap; // Will call DeleteObject;
        }
        else
        {
            CBitmap bmpIcon;
            bmpIcon.Attach(hBitmap);
            // Convert the bitmap to a transparent icon.
            HICON hIcon = CXTPTransparentBitmap(bmpIcon).ConvertToIcon();
            hIconHandle = hIcon; // Will call DestoyIcon.
        }
    }
   
    return !hIconHandle.IsEmpty();
}



-------------
PokerMemento - http://www.pokermemento.com/


Posted By: jimmy
Date Posted: 23 April 2010 at 8:10am
Hello,

Thanks for answer.
But this doesn't help.
My old function use this for fill a own CImageList (with ID's) with
using ImageManager to Load from toolbar (with id's).
Now i have add my own function loading toolbar id's.

But i think, it's not correct from CJ to return no ICON.
CJ can remove this function an can add a new function.
CXTPImageManagerIcon* pIcon = pCommandBars->GetImageManager()->GetImage(ID_COLOR_FORE);
HICON hIcon1 = pIcon->CreateIcon();

  Jimmy



Posted By: jimmy
Date Posted: 20 September 2010 at 9:08am
Hello,

Any solution for this ?
We add all your bmp, ico, Toolbar icons, ... to the ImageManager.
But how can i get a HICON from the ImageManager ?
I'll add the Icon to a dialog.

  Jimmy



Posted By: Oleg
Date Posted: 27 September 2010 at 7:30am
Hi,

Yes, now all icons locates in single GDI object.

Please copy it first when you need single icon:

CXTPImageManagerIcon* pIcon = pCommandBars->GetImageManager()->GetImage(ID_COLOR_FORE);

CXTPImageManagerIconHandle handle;
handle.CopyHandle(pIcon->GetIcon());
HICON hIcon1 = handle;


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: jimmy
Date Posted: 27 September 2010 at 11:02am
Hello Oleg,

Thanks for answer, that work great.
i've a little wish.
please add
    HICON Detach()
    {
        HICON hIcon = m_hIcon;
        m_hIcon = NULL;
        return hIcon;
    }
to CXTPImageManagerIconHandle class.

Thanks
  Jimmy



Posted By: Oleg
Date Posted: 28 September 2010 at 12:58am
Hi,

Added.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: jimmy
Date Posted: 28 September 2010 at 3:30am
Great,

Thanks Oleg.

   Jimmy


Posted By: jimmy
Date Posted: 01 October 2010 at 2:18am
Hi Oleg,

Have one more trouble with this.
CopyHandle does not create a HICON, if the ImageIcon is a alpha bitmap.

Now we use this.
static HICON CreateAlphaIcon(HBITMAP hBitmap, DWORD dwWidth,
DWORD dwHeight)
{
// dwWidth & Height could be extract from HBITMAP

// Create an empty mask bitmap. HBITMAP hMonoBitmap = CreateBitmap(dwWidth, dwHeight, 1, 1, NULL); // Fill icon info. ICONINFO ii; ii.fIcon = TRUE; ii.xHotspot = 0; ii.yHotspot = 0; ii.hbmMask = hMonoBitmap; ii.hbmColor = hBitmap; // Create the alpha icon with the alpha DIB section. HICON hAlphaIcon = CreateIconIndirect(&ii); // Delete mask bitmap. DeleteObject(hMonoBitmap); return hAlphaIcon; } class CXTPImageManagerIconHandleEx : public CXTPImageManagerIconHandle { public: HICON CreateIcon() { // if (m_hIcon == NULL) { // Temporären Handle (Kopie) erzeugen. CXTPImageManagerIconHandleEx temp; temp.CopyHandle(*this); // Wurde die Bitmap bereits in ein Icon konvertiert? if (temp.GetIcon() != NULL) // Das HICON extrahieren und setzen. m_hIcon = temp.Detach(); // Gibt es nur ein Bitmap, dann handelt es sich um ein Bitmap mit Alpha Channel. else if (temp.GetBitmap() != NULL) // Konvertieren des Alpha Bitmaps in ein Icon und setzen des Handle. m_hIcon = CreateAlphaIcon(temp.GetBitmap(), temp.GetExtent().cx, temp.GetExtent().cy); else _ASSERTE(FALSE && _T("Bitmap couldn't be converted into Icon")); } return m_hIcon; }
        HICON Detach() { HICON hIcon = m_hIcon; m_hIcon = NULL; return hIcon; } };

Please can you add also the code to create a HICON from alpha bitmap.

Thanks
  Jimmy





Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net