Duncan, you were right. I was missing the _Event in the interface name. That took care of the error message I was getting that prevented a successful build. It took me a few more minutes to realize that I forgot to make the same change in the m_appStatusEvents = line.
Here's what I have now:
Private m_appStatusEvents As IApplicationStatusEvents_Event
Protected Overrides Sub OnStartup()
m_appStatusEvents = TryCast(My.ThisApplication, IApplicationStatusEvents_Event)
AddHandler m_appStatusEvents.Initialized, AddressOf OnInitialized
End Sub
Private Sub OnInitialized()
clsGlobals.intUserRole = 0
If clsGlobals.intUserRole <= 1 Then 'readonly user
HideButtons()
End If
End Sub
Private Sub HideButtons()
Dim UID As New ESRI.ArcGIS.esriSystem.UID
Dim commandItem As ESRI.ArcGIS.Framework.ICommandItem
UID.Value = My.ThisAddIn.IDs.btnPushToGeo
commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
commandItem.Delete()
UID.Value = My.ThisAddIn.IDs.tolCreateNew
commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
commandItem.Delete()
UID.Value = My.ThisAddIn.IDs.btnUpdateOutfallSV
commandItem = My.ArcMap.Application.Document.CommandBars.Find(UID, False, False)
commandItem.Delete()
End Sub
(I've removed other code that OnInititalized will execute to determine the user role and assume for now that these buttons always get hidden. If I can get this part to work, I will add the extra code back in).
Here's the result:
1. Open ArcMap and show toolbar - all buttons are visible.
2. Leave toolbar open, close ArcMap, open ArcMap - buttons are hidden.
3. Close toolbar, close ArcMap - back to behavior number 1.
So, as long as ArcMap is closed with the toolbar visible, the buttons are hidden when ArcMap is re-opened. Whenever the toolbar needs to be opened by the user, the buttons are not hidden.
I guess I don't understand when OnInitialized actually gets run. But the AcmeExt example has a bunch of other checks going on to test whether Startup has run, etc. so I guess it's time to go back to that sample and keep expanding my code. Unfortunately, I'm no longer being paid to figure this out and the client was OK with the addin as delivered.
Thanks again for all of your help.