System Icons For TreeView Control?

System Icons For TreeView Control?

Post by Ron Bearr » Wed, 06 Mar 2002 00:23:33



This is probably easy stuff for old timers but I'm just a blossoming Windows
developer.

I am using a TreeView control and I'd like to use the same icons for my
nodes that the system uses. My TreeView control is just a directory browser
so I'd like to make it look like the OS it's running on.

I've seen a few other apps which do this so it has to be possible. Are there
any classes for this type of thing or does one need to invoke a Win32 call
somewhere?

thanks,
-rb

 
 
 

System Icons For TreeView Control?

Post by Jimco Add-in » Wed, 06 Mar 2002 00:29:34


Try an application like Microangelo (www.impactsoft.com) to extract icons
that you need.  Bear in mind that you may be reusing copyrighted materials.

--

Jim
Jimco Add-ins
http://www.jimcoaddins.com
Add-ins and utilities for Microsoft FrontPage


Quote:> This is probably easy stuff for old timers but I'm just a blossoming
Windows
> developer.

> I am using a TreeView control and I'd like to use the same icons for my
> nodes that the system uses. My TreeView control is just a directory
browser
> so I'd like to make it look like the OS it's running on.

> I've seen a few other apps which do this so it has to be possible. Are
there
> any classes for this type of thing or does one need to invoke a Win32 call
> somewhere?

> thanks,
> -rb


 
 
 

System Icons For TreeView Control?

Post by Ron Bearr » Wed, 06 Mar 2002 00:40:47



Quote:> Try an application like Microangelo (www.impactsoft.com) to extract icons
> that you need.  Bear in mind that you may be reusing copyrighted

materials.

Thanks Jimco,

I'd like to grab them at run-time since they are already a part of the
system...somewhere, and I've seen it done in other apps.

-rb

 
 
 

System Icons For TreeView Control?

Post by Vinn » Wed, 06 Mar 2002 00:59:42


I know exactly what you are talking about and it just might be something i
will persue in the future.

I dont know 100% how to do this, but i can give you some possible clues.

there is a registry setting for each type of file, if you look through here,
you will notice some registry entries have a "default icon" property.

also, i think that if you yank out this information from the system, there
is no copyright issues because you are just making a directory explorer
(just like windows)

if i come up with any more info i will post them

if you get a finished class, i would be interested in seeing it...

hope i can help,

Vinny




> > Try an application like Microangelo (www.impactsoft.com) to extract
icons
> > that you need.  Bear in mind that you may be reusing copyrighted
> materials.

> Thanks Jimco,

> I'd like to grab them at run-time since they are already a part of the
> system...somewhere, and I've seen it done in other apps.

> -rb

 
 
 

System Icons For TreeView Control?

Post by Rob You » Fri, 08 Mar 2002 22:59:15


Here's a class I found (somewhere on this ng I think) and modified to
add support for directories.  Call ExtractIcon.GetIcon(...).  If
you're using this for treeview icons, the extracted folder icons from
XP look pretty dire and I couldn't find anyway to display them with
the correct transparency. If folders are all you need, an embedded
resource containing bitmaps of the Win9x open and closed folders is a
neater way to go.

Rob.

/////////CLASS BEGINS///////
using System;
using System.Runtime.InteropServices;
using System.Drawing;

/// <summary>
/// Summary description for ExtractIcon.
/// </summary>
public class ExtractIcon
{
        [DllImport("Shell32.dll")]
        private static extern int  SHGetFileInfo
                (
                string pszPath,
                uint dwFileAttributes,
                out SHFILEINFO psfi,
                uint cbfileInfo,
                SHGFI uFlags
                );

        [StructLayout(LayoutKind.Sequential)]
                private struct SHFILEINFO
        {
                public SHFILEINFO(bool b)
                {
                        hIcon=IntPtr.Zero;iIcon=0;dwAttributes=0;szDisplayName="";szTypeName="";
                }
                public IntPtr hIcon;
                public int iIcon;
                public uint dwAttributes;
                [MarshalAs(UnmanagedType.LPStr, SizeConst=260)]
                public string szDisplayName;
                [MarshalAs(UnmanagedType.LPStr, SizeConst=80)]
                public string szTypeName;
        };

        private ExtractIcon()
        {
        }

        private enum SHGFI
        {
                SmallIcon   = 0x00000001,
                OpenIcon   = 0x00000002,
                LargeIcon   = 0x00000000,
                Icon    = 0x00000100,
                DisplayName   = 0x00000200,
                Typename   = 0x00000400,
                SysIconIndex  = 0x00004000,
                LinkOverlay = 0x00008000,              
                UseFileAttributes = 0x00000010
        }

        /// <summary>
        /// Get the associated Icon for a file or application, this method
always returns
        /// an icon.  If the strPath is invalid or there is no idonc the
default icon is returned
        /// </summary>
        /// <param name="strPath">full path to the file or directory</param>
        /// <param name="bSmall">if true, the 16x16 icon is returned
otherwise the 32x32</param>
        /// <param name="bOpen">if true, and strPath is a folder, returns the
'open' icon rather than the 'closed'</param>
        /// <returns></returns>
        public static Icon GetIcon(string strPath, bool bSmall, bool bOpen)
        {
                SHFILEINFO info = new SHFILEINFO(true);
                int cbFileInfo = Marshal.SizeOf(info);
                SHGFI flags;
                if (bSmall)
                        flags = SHGFI.Icon|SHGFI.SmallIcon;
                else
                        flags = SHGFI.Icon|SHGFI.LargeIcon;
                if (bOpen) flags = flags|SHGFI.OpenIcon;                

                SHGetFileInfo(strPath, 256, out info,(uint)cbFileInfo, flags);
                return Icon.FromHandle(info.hIcon);
        }

Quote:}

/////////CLASS ENDS///////
 
 
 

1. Retriving System icons from WinForm controls

Hi all,

I am trying to retrive system icons from within my simple WinForm
application.

First, I am building my own directory brower similar to the left
pane of explorer and I would like to retrive the correct icons to use
in my image list (or any other way of doing so). I need to icons that
are associated with directories and files in the system.

Second I am trying to retrive icons to use in the toolbar similar to
the one in internet explorer (in particular the back, stop and refresh
icons).

Is there any way of doing so in .NET?

Thanks

        --fabio

PS: right now I am running only on XP and I would be even happy with
a solution that uses XP icons (not all of which I can find parsing the
dlls).

--
-----------------------------------------------------------------------
Fabio Pellacini, PhD student - Program of Computer Graphics, Cornell U.

-----------------------------------------------------------------------

2. Home network question

3. User Control -- TreeView -- AutoPostBack: How To Prevent TreeView From Refreshing?

4. DP Studio

5. TREEVIEW control: is the font name and size hardcoded in treeview.htc?????

6. Performance issues

7. treeview: nodes with and w/o icons

8. PLEASE HELP DNS ERROR MESSAGES

9. TreeView Icons Look Really Bad

10. icons in TreeView

11. TreeView ImageList Icons have Black background

12. TreeView Icons and CheckBox

13. sizing TreeView image icons