Discussion:
CMFCRibbonButton and hIconSmall
(too old to reply)
Guglielmo Calligaro
2009-09-03 06:48:43 UTC
Permalink
I'm asking about the 2nd constructor.

CMFCRibbonButton(
UINT nID,
LPCTSTR lpszText,
HICON hIcon,
BOOL bAlwaysShowDescription=FALSE,
HICON hIconSmall=NULL,
BOOL bAutoDestroyIcon=FALSE,
BOOL bAlphaBlendIcon=FALSE
);

I want to use a 16x16 icon like this :

HICON hIcon =(HICON)LoadImage( AfxGetApp()->m_hInstance ,
MAKEINTRESOURCE(nID) , IMAGE_ICON , 16 , 16 , LR_SHARED );

CMFCRibbonButton* pBtnLine2Points = new CMFCRibbonButton( nID ,
_T("Line Two Points") , hIcon );

The icon is shown correctly but the button is still 32 x 32 .

I guess I must use the hIconSmall parameter of the constructor but how?
There is no example in MSDN, no description of the parameters, nothing!

Any help?
Guglielmo Calligaro
2009-09-03 07:34:46 UTC
Permalink
Post by Guglielmo Calligaro
The icon is shown correctly but the button is still 32 x 32 .
I discovered a bug in the MFC source code and it's about the
OnCalcTextSize / GetImageSize function of CMFCRibbonButton.

1) OnCalcTextSize perform this call

GetImageSize(RibbonImageLarge)

To check if the button got a 32x32 image.

2) GetImageSize then perform this check

if (m_hIcon != NULL)
{
CSize sizeIcon = type == RibbonImageLarge ? CSize(32, 32) :
CSize(16, 16);

<cut>

So if we have a valid m_hIcon (my case) the sizeIcon will be always
32 x 32 because of the RibbonImageLarge flag.

What to do? I can write my corrected version of CMFCRibbonButton but
there is also a way to report this to M$ ?

Thank you.
David Lowndes
2009-09-03 09:24:54 UTC
Permalink
Post by Guglielmo Calligaro
What to do? I can write my corrected version of CMFCRibbonButton but
there is also a way to report this to M$ ?
Yes, report it on connect: https://connect.microsoft.com/VisualStudio

Post a link back here to your report so that anyone else interested
can vote/verify it.

Dave
Guglielmo Calligaro
2009-09-03 14:02:41 UTC
Permalink
Post by David Lowndes
Post a link back here to your report so that anyone else interested
can vote/verify it.
Dave
Thank you Dave for your suggestion, here it is

http://tinyurl.com/lkt4qn
David Lowndes
2009-09-03 14:13:23 UTC
Permalink
Post by Guglielmo Calligaro
Thank you Dave for your suggestion, here it is
http://tinyurl.com/lkt4qn
Great.

Since you've already worked out where you think the error is in the
library code, I suggest that you add that information to your report -
help MS to get to the root of the problem ASAP :)

Dave
Scot T Brennecke
2009-09-04 05:05:13 UTC
Permalink
Post by Guglielmo Calligaro
Post by Guglielmo Calligaro
The icon is shown correctly but the button is still 32 x 32 .
I discovered a bug in the MFC source code and it's about the
OnCalcTextSize / GetImageSize function of CMFCRibbonButton.
1) OnCalcTextSize perform this call
GetImageSize(RibbonImageLarge)
To check if the button got a 32x32 image.
2) GetImageSize then perform this check
if (m_hIcon != NULL)
{
CSize(16, 16);
<cut>
So if we have a valid m_hIcon (my case) the sizeIcon will be always 32
x 32 because of the RibbonImageLarge flag.
What to do? I can write my corrected version of CMFCRibbonButton but
there is also a way to report this to M$ ?
Thank you.
Notwithstanding David's good instructions for reporting bugs, I don't agree that this is a "bug", per se. It is simply a design
that you don't like. It works as expected by the designers of the code. If you want to change the way it behaves, derive a class
from CMFCRibbonButton and override the virtual functions that do things that you don't like.
Guglielmo Calligaro
2009-09-04 06:52:33 UTC
Permalink
Post by Scot T Brennecke
Notwithstanding David's good instructions for reporting bugs, I don't agree
that this is a "bug", per se. It is simply a design that you don't like.
It works as expected by the designers of the code.
Why the 1st constructor allow big/small icons and the 2nd not?
Why is not written in the documentation?
Because of the code this function cannot return 16x16 then why use a
conditional operator that never works? This sounds more like a "bug" to
me.
Post by Scot T Brennecke
If you want to change the
way it behaves, derive a class from CMFCRibbonButton and override the virtual
functions that do things that you don't like.
That's what I did but at the same time it's better if M$ take a look
about that.
Scot T Brennecke
2009-09-07 08:38:32 UTC
Permalink
Post by Guglielmo Calligaro
Post by Scot T Brennecke
Notwithstanding David's good instructions for reporting bugs, I don't
agree that this is a "bug", per se. It is simply a design that you
don't like.
It works as expected by the designers of the code.
Why the 1st constructor allow big/small icons and the 2nd not?
Small icons aren't always needed, so a simpler ctor was offered, is my guess.
Post by Guglielmo Calligaro
Why is not written in the documentation?
Because the documentation sucks. It is almost worthless. Right now, you must read the code.
Post by Guglielmo Calligaro
Because of the code this function cannot return 16x16 then why use a
conditional operator that never works? This sounds more like a "bug" to me.
The small icon IS used by this class. Look over the documentation to see where and when it is used. They just didn't design it for
the use you want.
Post by Guglielmo Calligaro
Post by Scot T Brennecke
If you want to change the way it behaves, derive a class from
CMFCRibbonButton and override the virtual functions that do things
that you don't like.
That's what I did but at the same time it's better if M$ take a look
about that.
That's one of many hundreds of feature requests.
Guglielmo Calligaro
2009-09-10 06:54:18 UTC
Permalink
Post by Scot T Brennecke
Post by Guglielmo Calligaro
Why the 1st constructor allow big/small icons and the 2nd not?
Small icons aren't always needed, so a simpler ctor was offered, is my guess.
Why the 2nd constructor got an hICON for small icons but when you try
to use it simply the icon is not visualized. Why have a parameter in
the constructor if is absolutely ignored?
Post by Scot T Brennecke
Post by Guglielmo Calligaro
Why is not written in the documentation?
Because the documentation sucks. It is almost worthless. Right now, you
must read the code.
Exactly what I did, reading the code you can clearly see a bug.
Post by Scot T Brennecke
The small icon IS used by this class. Look over the documentation to see
where and when it is used. They just didn't design it for the use you want.
Nope, there is a bug in the code, otherwise the class will do exactly
what expected.
Post by Scot T Brennecke
That's one of many hundreds of feature requests.
That's a bug not a feature
Scot T Brennecke
2009-09-10 08:03:27 UTC
Permalink
Post by Scot T Brennecke
Post by Guglielmo Calligaro
Why the 1st constructor allow big/small icons and the 2nd not?
Small icons aren't always needed, so a simpler ctor was offered, is my guess.
Why the 2nd constructor got an hICON for small icons but when you try to
use it simply the icon is not visualized. Why have a parameter in the
constructor if is absolutely ignored?
Post by Scot T Brennecke
Post by Guglielmo Calligaro
Why is not written in the documentation?
Because the documentation sucks. It is almost worthless. Right now,
you must read the code.
Exactly what I did, reading the code you can clearly see a bug.
Post by Scot T Brennecke
The small icon IS used by this class. Look over the documentation to
see where and when it is used. They just didn't design it for the use
you want.
Nope, there is a bug in the code, otherwise the class will do exactly
what expected.
Post by Scot T Brennecke
That's one of many hundreds of feature requests.
That's a bug not a feature
I'm going to need you to explain the bug to me. All I see is that you want it to do something it wasn't designed to do.
Guglielmo Calligaro
2009-09-10 10:19:10 UTC
Permalink
Post by Scot T Brennecke
I'm going to need you to explain the bug to me. All I see is that you want
it to do something it wasn't designed to do.
I guess you better know that bugs not only shown error messages or stop
the execution of the software but also are when the result is not as
expected.

Whe have two similar constructor : one with index icons and the 2nd
with handle.

Because there is no documentation about how to use the 2nd constructor
I did some test with no working results so I wrote the report to
Microsoft and they reply with this example
Post by Scot T Brennecke
CMFCRibbonButton* pButtonA = new CMFCRibbonButton(ID_TESTA, L"A", NULL,
FALSE, hIconA);
then the icons will be treated as 16x16 images and the buttons will line up
as you expect.
Pat Brenner
Visual C++ Libraries Development
But it doesn't work.
The problem is in CMFCRibbonButton::GetImageSize.
The purpose of this function is to return to the caller the size of the
icon so the correct alignement but there is a missing management for
hIconSmall (i've implemented my own working GetImageSize and now
everything is perfect).
So they say it must work but it doesn't.
I'm sorry bu you are the only one left thinking this was by design.
Scot T Brennecke
2009-09-11 04:49:04 UTC
Permalink
No need to define "bug" for me. I've been a software developer since 1977.
Did Pat Brenner say it was a bug? If so, then I'll agree. He is the developer who "owns" the MFC library right now. Do you have a
Connect bug report?
Post by Guglielmo Calligaro
Post by Scot T Brennecke
I'm going to need you to explain the bug to me. All I see is that you
want it to do something it wasn't designed to do.
I guess you better know that bugs not only shown error messages or stop
the execution of the software but also are when the result is not as
expected.
Whe have two similar constructor : one with index icons and the 2nd with
handle.
Because there is no documentation about how to use the 2nd constructor I
did some test with no working results so I wrote the report to Microsoft
and they reply with this example
Post by Scot T Brennecke
CMFCRibbonButton* pButtonA = new CMFCRibbonButton(ID_TESTA, L"A",
NULL, FALSE, hIconA);
then the icons will be treated as 16x16 images and the buttons will
line up as you expect.
Pat Brenner
Visual C++ Libraries Development
But it doesn't work.
The problem is in CMFCRibbonButton::GetImageSize.
The purpose of this function is to return to the caller the size of the
icon so the correct alignement but there is a missing management for
hIconSmall (i've implemented my own working GetImageSize and now
everything is perfect).
So they say it must work but it doesn't.
I'm sorry bu you are the only one left thinking this was by design.
Guglielmo Calligaro
2009-09-11 06:29:45 UTC
Permalink
Post by Scot T Brennecke
No need to define "bug" for me. I've been a software developer since 1977.
Did Pat Brenner say it was a bug? If so, then I'll agree. He is the
developer who "owns" the MFC library right now. Do you have a Connect bug
report?
He wrote me an example telling me it must work but the example doesn't
work and in the source code of MFC is 100% clear that it cannot work.

Sorry but I don't know how to explain this in a better way...
Scot T Brennecke
2009-09-12 04:26:11 UTC
Permalink
Post by Guglielmo Calligaro
Post by Scot T Brennecke
No need to define "bug" for me. I've been a software developer since 1977.
Did Pat Brenner say it was a bug? If so, then I'll agree. He is the
developer who "owns" the MFC library right now. Do you have a Connect
bug report?
He wrote me an example telling me it must work but the example doesn't
work and in the source code of MFC is 100% clear that it cannot work.
Sorry but I don't know how to explain this in a better way...
Based on the snippet of his reply, he told you that if you pass only the HICON for the small size, it will be used and the icons
will line up. He didn't say that the other function for getting the image size would give you the size of the small image.
Guglielmo Calligaro
2009-09-14 06:04:06 UTC
Permalink
Post by Scot T Brennecke
Based on the snippet of his reply, he told you that if you pass only the
HICON for the small size, it will be used and the icons will line up. He
didn't say that the other function for getting the image size would give you
the size of the small image.
So why to pass an hIcon if is not displayed?
Stop joking me please, ppl is working here...
Scot T Brennecke
2009-09-14 08:21:45 UTC
Permalink
Post by Guglielmo Calligaro
Post by Scot T Brennecke
Based on the snippet of his reply, he told you that if you pass only
the HICON for the small size, it will be used and the icons will line
up. He didn't say that the other function for getting the image size
would give you the size of the small image.
So why to pass an hIcon if is not displayed?
Stop joking me please, ppl is working here...
IT IS DISPLAYED! Just not where and when you want it to be. Please read the code. I'm done arguing about this.
Guglielmo Calligaro
2009-09-14 09:23:46 UTC
Permalink
Post by Scot T Brennecke
IT IS DISPLAYED! Just not where and when you want it to be. Please read the
code. I'm done arguing about this.
"Try the code" don't simply read it ... it doesn't work... no icon is
shown
o***@gmail.com
2016-04-15 20:27:30 UTC
Permalink
Post by Guglielmo Calligaro
Post by Scot T Brennecke
IT IS DISPLAYED! Just not where and when you want it to be. Please read the
code. I'm done arguing about this.
"Try the code" don't simply read it ... it doesn't work... no icon is
shown
Hi guys, sorry long time... Just to put a answer for posterity.

if (hIcon != nullptr)
pButao = new CMFCRibbonButton(uID, pluginName, hIcon, FALSE, hSmallIcon);
else
pButao = new CMFCRibbonButton(uID, pluginName, pCategory->GetSmallImages().AddIcon(hSmallIcon));
Loading...