开发者

VSTO: Refresh Outlook2010 ribbon button control label

I'm creating a Outlook2010 add-in that will display how many email in a folder let's call it foo and it have many sub folders (During ribbon load, i have aggregated all the item count from foo and its sub folders. I have no problem with this part. However, if a user drag and drop a email from let's say Inbox into foo folder or any of its sub folder or vice versa then the item count on the custom ribbon will not reflect.

I tried to use folder beforeitemmove event but i wasn't get it to fire and also since user can create as many sub folder under foo as they want. I don't think beforeitemmove开发者_如何学Python event will work.

Is there a way to update a ribbon control (button)


http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/9da68794-a026-49b7-b919-651dc231846c/

Calling invalidate might work?


For Word I just found, that calling Office::IRibbonUI::Invalidate() produces a GDI object leak. For all of my ribbon buttons, the corresponding getImage callback is invoked. It appears that Word does not free the old images.

I have not yet found a way for enabling / disabling ribbon buttons on the fly.


Yes, invalidate works. But when used in combination with a getImage callback for a button, this will leak GDI objects (2 GDI objects per refresh per button).

I just got working code though:

Use a global load image callback:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="OnLoadImage">

Defined as:

STDMETHOD(OnLoadImage)(BSTR imageName, IPictureDisp** ppdispImage);

resp.

[
    object,
    uuid(CE895442-9981-4315-AA85-4B9A5C7739D8),
    dual,
    nonextensible,
    helpstring("IRibbonCallback Interface"),
    pointer_default(unique)
]
interface IRibbonCallback : IDispatch{
    [id(0x00000001),helpstring("OnLoad Callback")] HRESULT OnLoad([in]IDispatch* pRibbonUIDispatch);
    [id(0x00000002),helpstring("Button Callback")] HRESULT RibbonButtonClicked([in]IDispatch* pRibbon);
    [id(0x00000003),helpstring("ToggleButton Callback")] HRESULT RibbonToggleButtonClicked([in]IDispatch* pRibbon,[in] VARIANT_BOOL *pvarfPressed);
    [id(0x00000004),helpstring("GetSmallCustomImage Callback")] HRESULT GetSmallCustomImage([in]IDispatch* pRibbon, [out, retval] IPictureDisp** ppdispImage);
    [id(0x00000005),helpstring("GetLargeCustomImage Callback")] HRESULT GetLargeCustomImage([in]IDispatch* pRibbon, [out, retval] IPictureDisp** ppdispImage);
    [id(0x00000006),helpstring("GetLabel Callback")] HRESULT GetCustomLabel([in]IDispatch* pRibbon, [out, retval] BSTR* pbstrLabel);
    [id(0x00000007),helpstring("ShowLabel Callback")] HRESULT GetShowLabel ([in]IDispatch* pRibbon, [out, retval] VARIANT_BOOL *pvarShowLabel);
    [id(0x00000008),helpstring("GetEnabled Callback")] HRESULT GetEnabled ([in]IDispatch* pRibbon, [out, retval] VARIANT_BOOL *pvarEnabled);
    [id(0x00000009),helpstring("GetVisible Callback")] HRESULT GetVisible ([in]IDispatch* pRibbon, [out, retval] VARIANT_BOOL *pvarVisible);
    [id(0x0000000A),helpstring("GetItemPressed Callback")] HRESULT GetItemPressed ([in]IDispatch* pRibbon, [out, retval] VARIANT_BOOL *pvarChecked);
    [id(0x0000000B),helpstring("GetScreentip Callback")] HRESULT GetScreentip ([in]IDispatch* pRibbon, [out, retval] BSTR *pbstrScreentip);
    [id(0x0000000C),helpstring("GetGroupImage Callback")] HRESULT GetGroupImage([in]IDispatch* pRibbon, [out, retval] IPictureDisp** ppdispImage);
    [id(0x0000000D),helpstring("OnLoadImage Callback")] HRESULT OnLoadImage([in]BSTR imageName, [out, retval] IPictureDisp** ppdispImage);
};

It appears, that when the image is loaded via the global loadImage callback, there is no resource leak. But when the image is loaded by the getImage callback of a button, the new image is correctly loaded but I earn a GDI object leak.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜