I am working with Add-Ins in ArcMap using VS2010 and C#. I have a question in regards to ArcObjects ICommandBar and ICommandItem classes. I've looked at these and have been able to produce code, that on button click, will select or activate a specified command item. So I know somethings about command bars. My question is how would I go about determining which command Item is active on a Command Bar? I didn't see any helpful mehtods in which to do so. Any help on this would be greatly appreciated.
UID thisID = new UID();
thisID.Value = "esriArcMapUI.SelectTool";
IDocument ThisDoc = ArcMap.Application.Document;
ICommandBars CommandBars = ThisDoc.CommandBars as ICommandBars;
CommandBars.Find(thisID);
ICommandItem myItem = CommandBars.Find(thisID) as ICommandItem;
if (myItem.Execute() == true)
{
messagebox.show("My select element tool is selected");
}
I finally found an answer to my problem, with help from @DJKRAZE. I was making this a little harder than it was and thinking about it way too hard. The code below can be used to return the currently selected tool in ArcMap (In my case I am returning the tooltip of the currently selected tool in my diagnostic window).
I call this function on a button click. So, When I launch ArcMap, I select a tool from the toolbar. I look into my diagnostic window and I'm able to see the tool tip for the selected tool. I will need to tweak a few things for my own benefit, but this would be the answer I am looking for. Hope this can be of some help to any one else.