I have an ArcMap 10.0 add-in in which I have a button that the user can place (using the Customize dialog in ArcMap) on any toolbar including user-created toolbars as well as standard ones or even 3rd party ones. They could even put multiple instances of this button on the same or many toolbars (what can I say, some people can be crazy).
I have some code I need to run on each
ICommandItem instance (to set its
FaceID property, see this question if interested) wrapping this button command.
How can I reliably find each of these instances?
Currently I only set the first (and only) one returned by
ICommandBars.Find, leaving the rest alone. Not the worst thing in the world, but less than ideal.
I thought I had a lead with this snippet (List ArcMap Visible Toolbars) but this only lists standard ArcMap toolbars (those in the 'ESRI Mx Command Bars' component category in the registry). From that I could iterate over each command item in each toolbar.
This approach could work if I could get it to list all toolbars including user-defined ones (which are not in any category as far as I can tell), and, admittedly less-importantly, 3rd party ones (which may or may not always be in the same category used by the snippet, I'm not sure).
I found this crusty old unanswered post from 2003 on the ESRI forums asking how to find user toolbars: "Detect user defined toolbars programmatically" -- don't you just hate dead ends?
Lastly I found an answer in this post, "looping through all commandbars", (from our own GIS.se member Kirk Kuykendall, no less) which looks promising but I can't see how to translate the CreateObject call to .NET, and crucially, it doesn't look like you can actually get an
ICommandBar reference from its items.
Any pointers would be greatly appreciated.