Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Get HICON from XTPImageManager
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Get HICON from XTPImageManager

 Post Reply Post Reply
Author
Message
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Topic: Get HICON from XTPImageManager
    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



Back to Top
znakeeye View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 July 2006
Status: Offline
Points: 1672
Post Options Post Options   Thanks (0) Thanks(0)   Quote znakeeye Quote  Post ReplyReply Direct Link To This Post 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/
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 28 September 2010 at 12:58am
Hi,

Added.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post Posted: 28 September 2010 at 3:30am
Great,

Thanks Oleg.

   Jimmy
Back to Top
jimmy View Drop Down
Senior Member
Senior Member


Joined: 11 November 2003
Location: Austria
Status: Offline
Points: 516
Post Options Post Options   Thanks (0) Thanks(0)   Quote jimmy Quote  Post ReplyReply Direct Link To This Post 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


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.