Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / December 2007

Tip: Looking for answers? Try searching our database.

Add-in: Programmatically change icon in solution explorer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreas Larsen - 11 Dec 2007 23:26 GMT
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 - 12 Dec 2007 08:35 GMT
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.

Signature

Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
.NET and ASP .NET code

Andreas Larsen - 12 Dec 2007 10:18 GMT
Thanks a bunch! I will definitely check it out and post a solution if I find
one.
Andreas Larsen - 14 Dec 2007 11:03 GMT
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 - 14 Dec 2007 11:59 GMT
> 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 - 14 Dec 2007 12:33 GMT
> 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.

Signature

Peter Macej
Helixoft - http://www.helixoft.com
VSdocman - Commenter and generator of class documentation for C#, VB
.NET and ASP .NET code

Alex Blekhman - 14 Dec 2007 13:26 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.