Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Toolbar and images
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Toolbar and images

 Post Reply Post Reply
Author
Message
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post Topic: Toolbar and images
    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 :-( )
Back to Top
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post 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?
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: 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
Back to Top
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post Posted: 17 April 2008 at 10:00am
:-)

Yeah, that wasn't really obvious from my post, but I do use toolbar's ImageManager :-)
Back to Top
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post 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?
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: 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
Back to Top
radcap View Drop Down
Newbie
Newbie


Joined: 16 April 2008
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote radcap Quote  Post ReplyReply Direct Link To This Post 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.

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.156 seconds.