Print Page | Close Window

Toolbar and images

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=10255
Printed Date: 03 July 2024 at 5:06am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Toolbar and images
Posted By: radcap
Subject: Toolbar and images
Date Posted: 16 April 2008 at 10:40am
Hello,
searching through topics I could not fully realize if I can make a true dynamic setup for toolbars:

I need a popup toolbar with xtpButtonIconAndCaption button styles, and it has to allow dynamic addition of buttons (say, for plugins). How can I set it up so I get icons displayed? Right now I can only see the captions, but no icons.

Can you tell me whether I can achieve such behavior and if I can, then how?

I use XTP v9.60 (and there are reasons that restrict me to this version :-( )



Replies:
Posted By: radcap
Date Posted: 17 April 2008 at 7:23am

If I wasn't too clear:

In the discussion there are advices to use ->ImageManager()->SetIcon(s) method to add images to the manager, and then all one needs is just to use CXTPControl::SetIconId() method.
 
I try to achieve this at runtime as this:
Plugin gets loaded and fetches a pointer to the toolbar. It may add controls to the toolbar, but I've been unable to attach icons to the controls.
 
If I understand all clear, the plugin needs first to SetIcon() to attach its icon to imagemanager and then just to call SetIconId() for the added control. But icon doesn't show up. What am I doing wrong?


Posted By: Oleg
Date Posted: 17 April 2008 at 8:45am
Hi,
try instead of global XTPImageManger call
 
m_wndToolBar.GetImageManager()->SetIcons(...);
 
just set icon with Id of button and you don't need to call SetIconId for this case.


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


Posted By: radcap
Date Posted: 17 April 2008 at 10:00am
:-)

Yeah, that wasn't really obvious from my post, but I do use toolbar's ImageManager :-)


Posted By: radcap
Date Posted: 17 April 2008 at 10:46am
Here's the code from main application (not a plugin), the problem resides with it as well:


HBITMAP hBitmap = ::LoadBitmap(GetModuleHandle(0), MAKEINTRESOURCE(IDR_BITMAP_XXX));

if (hBitmap)
{
    CXTPImageManagerIconHandle xtpIconHandle(hBitmap);
    pCAppModeToolbar->GetImageManager()->SetIcon(xtpIconHandle,1);
    pCAppModeToolbar->GetImageManager()->SetIcon(xtpIconHandle,2);
}

CXTPControl* pControl = pCAppModeToolbar->GetControls()->Add(xtpControlSplitButtonPopup,1);

pControl->SetCaption(_T("Action 1"));
pControl->SetStyle(xtpButtonIconAndCaption);
// pControl->SetIconId(1); // doesn't help

// Add second button to drop-down toolbar
pControl = pControl->GetCommandBar()->GetControls()->Add(xtpControlButton,2);
pControl->SetCaption(_T("Action 2"));
// pControl->SetIconId(2); // doesn't help



Posted By: radcap
Date Posted: 17 April 2008 at 1:16pm
Hi again.

Hmm, I think now I need some explanation:
in the code I posted earlier I used SetIcon method. The bitmap itself, though is a toolbar resource, is an image of a single button (so I wanted to set it twice for both buttons).
I changed the code to this:


//...
// Was:
//
// HBITMAP hBitmap = ::LoadBitmap(GetModuleHandle(0),
//     MAKEINTRESOURCE(IDR_BITMAP_XXX));
// pCAppModeToolbar->GetImageManager()->SetIcon(
//   CXTPImageManagerIconHandle(hBitmap), 1);
//
// Now:

static UINT commonBtns = { 1 };

pCAppModeToolbar->GetImageManager()->SetIcons(
    IDR_BITMAP_XXX,
    commonBtns,
    _countof(commonBtns),
    CSize(16,16));


and all went good, I've got my image displayed on the button. After that, I've found out that to set image for the second button (which in fact is in the different command bar, thus I'm showing only one button in the code here) I need to use another ImageManager, but that means little now, because the idea itself works.

So, why doesn't the SetIcon work as I expected it would? LoadBitmap definetly returned the needed bitmap, I've checked that out. Is this an issue with XTP 9.60, or I still did something wrong?


Posted By: Oleg
Date Posted: 17 April 2008 at 1:22pm
This conversion:
CXTPImageManagerIconHandle xtpIconHandle(hBitmap);
only works for alpha bitmaps.
 
use SetIcons method instead.


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


Posted By: radcap
Date Posted: 17 April 2008 at 1:36pm
Oh, that explains things :-)

Thanks for your help and immense amount of info on the forum, I think I wouldn't find the solution so quick without it.




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