Discussion:
Add-in: Programmatically change icon in solution explorer
(too old to reply)
Andreas Larsen
2007-12-11 23:26:51 UTC
Permalink
I am trying to write an add-in for Subversion in Visual Studio, that keeps
track of which files are being worked on by project members.

I want to add icons to the files in the Solution Explorer, to flag whether
they are being worked on or not, but I can't find out how..

I looked up UIHierarchy and UIHierarchyItem which allows you to traverse the
tree in the Solution Explorer, but there does not seem to be a way to
manipulate the contents or the way the tree is being drawn?

Any ideas are most welcome,
thanks!
Peter Macej
2007-12-12 08:35:52 UTC
Permalink
AnkhSVN is a Subversion add-in for Visual Studio. It also uses overlay
icons and it is open source. So you can see their code how it's done.
--
Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
.NET and ASP .NET code
Andreas Larsen
2007-12-12 10:18:50 UTC
Permalink
Thanks a bunch! I will definitely check it out and post a solution if I find
one.
Andreas Larsen
2007-12-14 11:03:28 UTC
Permalink
I had a look at AnkhSVN (great add-in by the way), and I found what I was
looking for.
As I feared, the process of manipulating icons in the Solution Explorer
treeview is not straight forward.

The way AnkhSVN solves the case is roughly like this:

- Obtain the solution explorer window name, from the EnvDTE.Window reference
of the window
- Get an IntPTR reference to the main window
- Search for the solution explorer (location depends on how it is docked)
- Use FindWindowEx() from Win32 COM and traverse all main window childs
and floating windows until it is found (using the solution explorer window
name)
- When it is found, locate its UIHierarchy child window by name
("VsUIHierarchyBaseWin")
- And then finally locate the treeview window ("SysTreeView32") which is a
child of UIHierarchy

- Once you have a handle to the tree view, you may use Win32 COM method
calls such as SendMessage(), in order to set its image list
(TVM_SETIMAGELIST) and traverse the tree view (TVM_GETNEXTITEM).

What we want to do in order to change icons of the solution explorer items,
is replace the image list of the treeview with a self-drawn bitmap strip,
which can hold several icons in one bitmap.

Once the image list is set, we can set the icon for each item in the tree
view by traversing the tree view and using sending the message TVM_SETITEM
for each item.
AnkhSVN uses status icons and overlay icons in order to independently draw
two different statuses on a single item (such as "Modified" and
"Read-only").
We bake the overlay and base image indexes into a TVITEMEX struct, and pass
that as value to the message.


For a complete understanding you should consult the code of AnkhSVN.
Classes of interest are:

Ankh.Connect (obviously)
Ankh.Solution.Explorer (convenience methods
for the solution explorer)
Ankh.Solution.SolutionExplorerTreeNode (abstraction of the solution
explorer nodes)
Ankh.UI.Win32TreeView (tree view abstraction)
Ankh.StatusImages (tree view image
list enumeration)
Ankh.status_icons.bmp (the icons)
Utils.Win32 (Win32 COM
methods and constants exposed)


Hope this may help some guys out.. peace!

Best regards,
Andreas Larsen
Alex Blekhman
2007-12-14 11:59:20 UTC
Permalink
Post by Andreas Larsen
I had a look at AnkhSVN (great add-in by the way), and I
found what I was looking for.
As I feared, the process of manipulating icons in the
Solution Explorer treeview is not straight forward.
[...]
Your explanation is all right with minor correction. These
methods are not Win32 _COM_ methods. These are plain Win32
API function calls.

Recently I have made a simple VS add-in with C#. I have
encountered a lot of limitations, too. Though my add-in is
quite simple, I was forced to fall back on PInvoke more than
I ever expected. Probably using VS Extensibility SDK would
have solved many problems, but it is an overkill for
otherwise often simple tasks.

Alex
Peter Macej
2007-12-14 12:33:43 UTC
Permalink
Post by Alex Blekhman
I ever expected. Probably using VS Extensibility SDK would
have solved many problems, but it is an overkill for
otherwise often simple tasks.
You can use VS Extensibility SDK from your add-in without the need to
create VS package. You can call many VS services from your add-in, our
VSdocman does. See http://www.mztools.com/articles/2007/MZ2007015.aspx
how to do it.
--
Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
.NET and ASP .NET code
Alex Blekhman
2007-12-14 13:26:56 UTC
Permalink
Post by Peter Macej
You can use VS Extensibility SDK from your add-in without
the need to create VS package. You can call many VS
services from your add-in, our VSdocman does. See
http://www.mztools.com/articles/2007/MZ2007015.aspx how to
do it.
Thanks, this is useful tip. I already found numerous gems on
this site. Here is another one. :)

Alex

Loading...