Print Page | Close Window

Can I get the HBitmap from a toolbar button

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=14778
Printed Date: 22 June 2025 at 12:58am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Can I get the HBitmap from a toolbar button
Posted By: tralfaz
Subject: Can I get the HBitmap from a toolbar button
Date Posted: 20 July 2009 at 1:34pm
I have the ID to the toolbar button. Can I get the HBitmap associated with the button programmatically?

I tried this and HBitmap is always NULL.

    CXTPImageManagerIcon* pIcon = XTPImageManager()->GetImage( CmdID, 16);
    if (pIcon) {
        CXTPImageManagerIconHandle IconHandle = pIcon->GetIcon();
        CXTPImageManagerIconHandle IconCopy;
        IconCopy.CopyHandle(IconHandle);
        if (IconCopy != NULL) {
            hBM = (HBITMAP)IconCopy.GetBitmap();
        }
    }


-------------

XP Pro SP3 / VS2008 C++ / Xtreme CommandBars v13.1.0



Replies:
Posted By: Oleg
Date Posted: 22 July 2009 at 4:01am
Hi,
 
Maybe you have assiciated icon - not bitmap. check
IconCopy.GetIcon()

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


Posted By: tralfaz
Date Posted: 22 July 2009 at 9:08am
I've tried several different ways to extract the hbitmap from a toolbar.

I created the toolbar using:
    CXTPTabManagerItem* pItem = CreateToolbar(pCommandBars, pToolBar, Index, _TT("Main"), IDR_MAINFRAME3, true, true, false);

How do I get the hbitmap from one of the buttons using it's command ID?

I've tried this approach too
        CXTPControl* pCtrl = pCommandBars->FindControl(XTPControlType::xtpControlButton, CmdID, true, true);
        if (pCtrl) {
            CXTPImageManagerIcon* pIcon = pCtrl->GetImage();
            if (pIcon) {
                CXTPImageManagerIconHandle IconHandle = pIcon->GetIcon();


-------------

XP Pro SP3 / VS2008 C++ / Xtreme CommandBars v13.1.0


Posted By: Oleg
Date Posted: 24 July 2009 at 3:31am
Check this:
 
CXTPImageManagerIconHandle IconHandle = pIcon->GetIcon();
        CXTPImageManagerIconHandle IconCopy;
        IconCopy.CopyHandle(IconHandle);
       
      ASSERT(IconCopy.GetBitmap() || IconCopy.GetIcon());


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


Posted By: tralfaz
Date Posted: 24 July 2009 at 10:52am
Should pIcon come from
    CXTPImageManagerIcon* pIcon = XTPImageManager()->GetImage( CmdID, 16);

or

        CXTPControl* pCtrl = pCommandBars->FindControl(XTPControlType::xtpControlButton, CmdID, true, true);
        if (pCtrl) {
            CXTPImageManagerIcon* pIcon = pCtrl->GetImage();


or does it matter?


-------------

XP Pro SP3 / VS2008 C++ / Xtreme CommandBars v13.1.0


Posted By: tralfaz
Date Posted: 24 July 2009 at 2:11pm
Oleg,

That code did return an hIcon, at least it was not null. However, the hIcon would not display when draw with pDC->DrawState.

I was able to solve my problem by passing the pDC to pIcon->Draw(pDC, CPoint) - that worked!

Thanks


-------------

XP Pro SP3 / VS2008 C++ / Xtreme CommandBars v13.1.0



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