title: Control ribbon buttons for each opened window separately
body: <p>I'm writing an Outlook add-in that has its own ribbon with buttons defined in an xml manifest. Besides the main Outlook window (explorer), separate windows can be opened (inspectors) and all of them have the same ribbon. I would like to control the properties of ribbon buttons independently. But in my <code>getPressed</code> button handlers I always get the same ribbon object. And <code>OnRibbonLoad</code> is always called only once. So, what I would like to hypothetically see is that there is as many ribbons as the number of inspectors ( + explorer) there. In terms of behavior: imagine an explorer shows an email and there is also an inspector with another email in it. Both windows have the same ribbon, but I want to be able to enable/disable buttons in every window independently.</p>
  <p>Here is my manifest:</p>
  <pre><code>&lt;customUI xmlns=&quot;http://schemas.microsoft.com/office/2006/01/customui&quot; onLoad=&quot;OnRibbonLoad&quot;&gt;
    &lt;ribbon&gt;
      &lt;tabs&gt;
      &lt;tab idMso=&quot;%1&quot;&gt;
          &lt;group id=&quot;addin_group&quot; label=&quot;Title&quot; getImage=&quot;GetAddinGroupImage&quot;&gt;
              &lt;toggleButton id=&quot;addin-enable-toggle&quot;
                  size=&quot;large&quot;
                  getLabel=&quot;GetAddinEnabledStatusLabel&quot;
                  onAction=&quot;OnAddinToggled&quot;
                  getPressed=&quot;GetAddinEnabled&quot;
                  getImage=&quot;GetAddinEnabledImage&quot;
                  getEnabled=&quot;GetAddinTogglePermission&quot;
                  /&gt;
              &lt;button id=&quot;ButtonSetting&quot;
                  getImage=&quot;GetSettingButtonImage&quot;
                  size=&quot;large&quot;
                  label=&quot;Configure&quot;
                  screentip=&quot;Configure&quot;
                  supertip=&quot;Opens the configuration dialog.&quot;
                  onAction=&quot;OnSettingButtonClicked&quot;
                  getEnabled=&quot;GetAddinValid&quot;
                  /&gt;
              &lt;button id=&quot;ButtonRefresh&quot;
                  getImage=&quot;GetRefreshButtonImage&quot;
                  size=&quot;large&quot;
                  label=&quot;Refresh&quot;
                  screentip=&quot;Refresh scan result&quot;
                  supertip=&quot;Remeasure the threat level of the current item.&quot;
                  onAction=&quot;OnRefreshMailResults&quot;
                  getEnabled=&quot;GetAddinValid&quot;
                  /&gt;
              &lt;button id=&quot;ButtonReport&quot;
                  getImage=&quot;GetButtonReportImage&quot;
                  size=&quot;large&quot;
                  label=&quot;Report&quot;
                  screentip=&quot;Report mail&quot;
                  supertip=&quot;Reports the opened mail.&quot;
                  onAction=&quot;OnButtonReportPressed&quot;
                  getEnabled=&quot;GetEmailReportingEnabled&quot;
                  /&gt;
              &lt;button id=&quot;ButtonUnlock&quot;
                  getImage=&quot;GetButtonUnlockImage&quot;
                  size=&quot;large&quot;
                  label=&quot;Unlock&quot;
                  screentip=&quot;Unlock mail&quot;
                  supertip=&quot;Unlocks the opened mail.&quot;
                  onAction=&quot;OnButtonUnlockPressed&quot;
                  getEnabled=&quot;GetEmailUnlockingEnabled&quot;
                  /&gt;
          &lt;/group&gt;
        &lt;/tab&gt;
      &lt;/tabs&gt;
    &lt;/ribbon&gt;
  &lt;/customUI&gt; 
  </code></pre>
  <p><code>%1</code> in <code>&lt;tab idMso=&quot;%1&quot;&gt;</code> is replaced on either <code>TabReadMessage</code> or <code>TabMail</code> depending on <code>ribbonId</code> value that I get in IRibbonExtensibility::getCustomUI function:</p>
  <pre><code>//IRibbonExtensibility Methods
  STDMETHODIMP CConnect::GetCustomUI(BSTR RibbonID, BSTR *RibbonXml)
  {
      if(!RibbonXml)
      {
          return E_POINTER;
      }
  
      //Get the ID of the ribbon that a custom UI is being requested for
      QString ribbonIdStr = BSTR2QString(RibbonID);
  
      static QMap&lt;QString, QString&gt; ribbonViews;
  
      if(ribbonViews.isEmpty()) { //initialize
          ribbonViews[&quot;Microsoft.Outlook.Mail.Read&quot;] = &quot;TabReadMessage&quot;;
          ribbonViews[&quot;Microsoft.Outlook.Explorer&quot;] = &quot;TabMail&quot;;
      }
  
      if(ribbonViews.contains(ribbonIdStr)) {
          *RibbonXml = XmlResource2ComBSTR(ASSET_RIBBON_MANIFEST, &amp;ribbonViews[ribbonIdStr]);
      }
  
      return S_OK;
  }
  </code></pre>