Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CMFCRibbonButton constructor with HICON doesn't work properly

88 views
Skip to first unread message

[d3m0n]

unread,
Nov 13, 2008, 7:39:01 AM11/13/08
to
Hi
I'm using VS2008 and the MFC Feature Pack. I am trying to add 5 buttons A,
B, C, D and E to the ribbon. Each button has an image which I want to appear
next to the text.

I managed to get the first constructor of CMFCRibbonButton (the one with 2
ints and a BOOL) to work fine. The items are added to the ribbon panel one
below the other, like this:
A D
B E
C

However I would actually prefer to use the second constructor (the one with
HICONs) because I already have some HICONs that I can get from a DLL, which I
want to use as the images.

But when I tried using HICONs in the constructor, the buttons were added
*alongside* each other, like this:
A B C D E

I tried stepping into the MFC code and it seems that for buttons created
using the HICON constructor, CMFCRibbonButton::m_bIsLargeImage gets set to
TRUE. Even though my icons are only 16x16.

Here's some example code to demonstrate the problem:


//add category to ribbon
CMFCRibbonCategory* pCategoryTest =
m_wndRibbonBar.AddCategory(L"TestCategory", 0, 0);

//add panel to category
CMFCRibbonPanel* pPanelTest = pCategoryTest->AddPanel(L"TestPanel");

//load some 16x16 icons from resources
HICON hIcon1 = (HICON)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TEST1), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON),
::GetSystemMetrics(SM_CYSMICON), 0);
HICON hIcon2 = (HICON)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDI_TEST2), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON),
::GetSystemMetrics(SM_CYSMICON), 0);

//create buttons
CMFCRibbonButton* pButton1 = new CMFCRibbonButton(ID_TEST1, L"Test1",
hIcon1);
CMFCRibbonButton* pButton2 = new CMFCRibbonButton(ID_TEST2, L"Test2",
hIcon2);

//add buttons to panel
pPanelTest->Add(pButton1);
pPanelTest->Add(pButton2);


Please could anyone give me some suggestions?

Jonathan Wood

unread,
Nov 14, 2008, 11:34:43 AM11/14/08
to
I'm not sure what you are seeing. I haven't tried using icons for this.

If it were me, I'd download IconWorks, transfer all my icon images to a
high-color toolbar image with full alpha channel and be done with it.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

"[d3m0n]" <[d3m0n]@discussions.microsoft.com> wrote in message
news:F3F0EC11-7D79-4044...@microsoft.com...

[d3m0n]

unread,
Nov 17, 2008, 5:03:01 AM11/17/08
to
Thanks for your suggestion. I know using one toolbar for all icons works
fine, and obviously I'd do that if I could.

The trouble is, I can't because my icons are obtained on-the-fly from
different DLLs.

The second constructor does take a HICON so in theory it should work.
(however I understand that theory != practice :)

This is a bug in MFC right?

[d3m0n]

unread,
Nov 25, 2008, 4:50:01 AM11/25/08
to
"[d3m0n]" wrote:
> This is a bug in MFC right?

Anyone?

0 new messages