I'm building a Visual Studio extension, which should add my tool button on a ToolBar or ToolStrip.
There are 2 cases:
first case, add my red button to the toolbar/toolstrip which was added by another extension (Visual Micro), see image 1.
second case, add my red button to the Properties toolbar/toolstrip of the Visual Studio UI, see image 2.
Image 1:
Image 2:
I tried to implement the second case, but without any positive results.
Here is the code:
EventHandler btnClick = new EventHandler(delegate (Object o, EventArgs a)
{
//snip
});
System.Drawing.Image img = System.Drawing.Image.FromFile("W:\\...\\red_btn.png");
ToolStripButton btn = new ToolStripButton("My Button", img, btnClick, "RedButton");
btn.Width = 32;
btn.Height = 32;
btn.Visible = true;
IntPtr hProperties = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "WindowsForms10.Window.8.app.0.c940ee_r43_ad1", null) ;
ToolStrip toolStrip = (ToolStrip)ToolStrip.FromHandle(hProperties);
if (toolStrip != null)
{
toolStrip.Items.Add(btn);
toolStrip.Refresh();
toolStrip.Visible = true;
}
When I execute the above code from my ToolWindow1Control init() method, nothing happens. What I tried was to find the handle of toolbar from Properties window and add my button to it. But that is not working.
I'm expecting to add the red button to the Properties window's toolbar. This button should execute some code related to the source file which is currently viewed. And this is the second case.
For the first case I don't have any idea how to find the handle of that toolbar to add my button.
Please help.
CodePudding user response:
There aren't any toolbar or toolstrip HWNDs in WPF windows. What you are trying to do is not possible. If you need to add any visuals to Visual Studio's GUI, use the public API. This isn't just better, it's the only way to do this.