Update ribbon when host is not focused

Add-in Express™ Support Service
That's what is more important than anything else

Update ribbon when host is not focused
 
nwein




Posts: 548
Joined: 2011-03-28
If I set my COM add-in to update anything on my custom ribbon, the update will only be effective when the host is focused.
Is it possible to force the ribbon to update without focusing the host (Excel)?
Excel 2010, 32-bit, latest ADX 6.
Posted 29 Oct, 2012 15:26:30 Top
Andrei Smolin


Add-in Express team


Posts: 16814
Joined: 2006-05-11
Hello Nir,

You can try caching the IRibbonUI object (it's supplied in the OnRibbonLoaded event of the add-in module) and call IRibbonUI.Invalidate() in an appropriate moment. Please let me know whether this works for you.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 30 Oct, 2012 02:29:57 Top
nwein




Posts: 548
Joined: 2011-03-28
Thanks Andrei, however it doesn't seem to work.
I can give you a simple way of reproducing it:

1. Create a System.Windows.Forms.Timer in your COM addin and set it to have 1 second interval.
2. Create an ADXRibbonButton in your ribbon.
3. On Timer tick set the button visibility to opposite of current visibility (i.e. flashing)
4. Launch your host (Excel or whatnot) and note that the button appears and disappears every second (as we want it to).
5. Switch your focus on some other window (i.e. your broswer, visual studio, anything else).
6. Observe that the button doesn't switch on and off again anymore.
7. Focus your host again and observe that the button keeps working as intended (i.e. appear/disappear).

You can add IRibbonUI invalidate to the timer tick (grabbing the IRibbonUI from the load event) but that won't make any difference.
Posted 30 Oct, 2012 12:26:46 Top
Andrei Smolin


Add-in Express team


Posts: 16814
Joined: 2006-05-11
Nir,

I assume this is by design.

[CODEprivate Timer timer1;
private ADXRibbonTab adxRibbonTab1;
private ADXRibbonGroup adxRibbonGroup1;
private ADXRibbonButton adxRibbonButton1;
private ADXRibbonButton adxRibbonButton2;

...

private void timer1_Tick(object sender, EventArgs e)
{
adxRibbonButton1.Visible = !adxRibbonButton1.Visible;
}

private void adxRibbonButton2_OnClick(object sender, IRibbonControl control, bool pressed)
{
timer1.Enabled = !timer1.Enabled;
}[/CODE]

Please see how the add-in above behaves for me; pay attention to the moments when the cursor is outside of the host window:

http://www.add-in-express.com/files/support/2012-10-31_1109.swf

You can download this file and open it via File | Open in IE.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Oct, 2012 03:17:43 Top
nwein




Posts: 548
Joined: 2011-03-28
Yes, this is exactly what I was trying to explain.
If you're saying its by design then it's too bad, it means that if you don't have your host focused then the ribbon won't be able to automatically update in the background.
I guess it's doable to focus the host when something changes on the ribbon using some windows API such as the handle to the host etc., but I'm not sure that this is the right approach.
Thanks for the effort though, I thought there might be a simple workaround for this.
Posted 31 Oct, 2012 10:44:19 Top
Andrei Smolin


Add-in Express team


Posts: 16814
Joined: 2006-05-11
Nir,

Consider using a pane instead.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 31 Oct, 2012 10:54:46 Top