CMFCRibbonStatusBar中添加图片按钮

今天遇到了问题,网上down的

Here's how it works:

1. Create aCMFCRibbonButtonsGroup that will hold the status icon and add it to CMFCRibbonStatusBar

2. Create a CMFCToolBarImagesobject and add status icons via AddIcon() .

3. Register theCMFCToolbarImages to the RibbonButtonsGroup using SetImages() .For a status Icon, the pHotImages parameter may be set to NULL, since thebutton won't get a message handler assigned anyway. Note however, that both thefirst and the second parameter must be set. If the third is omitted, the iconwill be grayed out for disables buttons and if the first is omitted, no icons willbe displayed at all.

4. Create a new CMFCRibbonButtonand add it to the ButtonsGroup via AddButton() .Do *not* assign an Icon to it.

5. Obtain a pointer to thebutton using CMFCRibbonButtonsGroup::GetButton() .Then call CMFCRibbonButton::SetImageIndex() withthe appropriate index of the icon in the ToolBarImages object.

 

This approach works just fine,except for one minor detail: I was using 16x16 icons as status icons andnoticed that they get cropped on display to 16x15, i.e. the bottom row ofpixels is not displayed. A quick fix for this would be to specify the icon'sdimensions as 16x15 when callingLoadImage() ,but I wonder why this is necessary in the first place. I guess theCMFCRibbonButtonsGroup is to blame for this, though I don't know that classwell enough to claim anything for certain.

Edit:Turns out it really is CMFCToolBarImages's fault. For some reason, the defaulticon size here is 16x15. This can be changed by callingCMFCToolBarImages::SetImageSize() before adding the icons.

posted on 2010-12-20 23:08  C杨阳  阅读(735)  评论(0编辑  收藏  举报

导航