Shell File and Folder Images 
Author Message
 Shell File and Folder Images

I have populated a TreeView control with the logical drives discovered on
the system which can be expanded to view child nodes of the subdirectories
and files contained there in.  It works great so far and is a lot easier to
do than with C++. The only thing I can't seem to figure out is how to
associate an ImageList with the shell icons that appear in Windows Explorer.
I could always create a standard set of images, but that seems a little
tacky considering that those images vary from system to system.

---------------------------------------------------------------------------
In C++ I could do something like this:

 SHFILEINFO shFinfo;

 HIMAGELIST hImageList = (HIMAGELIST) SHGetFileInfo(
         _T("C:\\"),
         0,
         &shFinfo,
         sizeof( shFinfo ),
         SHGFI_SYSICONINDEX |
         SHGFI_SMALLICON
 );

 SetImageList( m_hImageList, TVSIL_NORMAL );

----------------------------------------------------------------------------
I need some advice from an expert about how I could attach a C# ImageList to
the system icons to display in my tree.

Thanks in advance,
Dean



Sat, 25 Jun 2005 04:25:40 GMT  
 Shell File and Folder Images
Dean,

    I wouldn't use the SHGFI_SYSICONINDEX flag, but rather just the
SHGFI_SMALLICON flag.  The reason for this is that when you call
SHGetFileInfo, you can get the handle to the icon on the return value.  Once
you have this, you can call the static FromHicon method on the Bitmap class
to get an instance of a Bitmap representing the image.  Once you have that,
you can add it to the Imagelist like any other image.

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> I have populated a TreeView control with the logical drives discovered on
> the system which can be expanded to view child nodes of the subdirectories
> and files contained there in.  It works great so far and is a lot easier
to
> do than with C++. The only thing I can't seem to figure out is how to
> associate an ImageList with the shell icons that appear in Windows
Explorer.
> I could always create a standard set of images, but that seems a little
> tacky considering that those images vary from system to system.

> --------------------------------------------------------------------------
-
> In C++ I could do something like this:

>  SHFILEINFO shFinfo;

>  HIMAGELIST hImageList = (HIMAGELIST) SHGetFileInfo(
>          _T("C:\\"),
>          0,
>          &shFinfo,
>          sizeof( shFinfo ),
>          SHGFI_SYSICONINDEX |
>          SHGFI_SMALLICON
>  );

>  SetImageList( m_hImageList, TVSIL_NORMAL );

> --------------------------------------------------------------------------
--
> I need some advice from an expert about how I could attach a C# ImageList
to
> the system icons to display in my tree.

> Thanks in advance,
> Dean



Sat, 25 Jun 2005 04:59:08 GMT  
 Shell File and Folder Images
Thanks for the advice! I'll try it

Dean



Quote:
> Dean,

>     I wouldn't use the SHGFI_SYSICONINDEX flag, but rather just the
> SHGFI_SMALLICON flag.  The reason for this is that when you call
> SHGetFileInfo, you can get the handle to the icon on the return value.
Once
> you have this, you can call the static FromHicon method on the Bitmap
class
> to get an instance of a Bitmap representing the image.  Once you have
that,
> you can add it to the Imagelist like any other image.

>     Hope this helps.

> --
>                - Nicholas Paldino [.NET/C# MVP]



> > I have populated a TreeView control with the logical drives discovered
on
> > the system which can be expanded to view child nodes of the
subdirectories
> > and files contained there in.  It works great so far and is a lot easier
> to
> > do than with C++. The only thing I can't seem to figure out is how to
> > associate an ImageList with the shell icons that appear in Windows
> Explorer.
> > I could always create a standard set of images, but that seems a little
> > tacky considering that those images vary from system to system.

> --------------------------------------------------------------------------
> -
> > In C++ I could do something like this:

> >  SHFILEINFO shFinfo;

> >  HIMAGELIST hImageList = (HIMAGELIST) SHGetFileInfo(
> >          _T("C:\\"),
> >          0,
> >          &shFinfo,
> >          sizeof( shFinfo ),
> >          SHGFI_SYSICONINDEX |
> >          SHGFI_SMALLICON
> >  );

> >  SetImageList( m_hImageList, TVSIL_NORMAL );

> --------------------------------------------------------------------------
> --
> > I need some advice from an expert about how I could attach a C#
ImageList
> to
> > the system icons to display in my tree.

> > Thanks in advance,
> > Dean



Sat, 25 Jun 2005 08:19:13 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. thumbnail image from a Shell folder

2. File/Folder path of a file/folder on the explorer

3. Shell Extensions donot get called in Web Folders

4. TOUGH QUESTION: Adding a virtual folder to the Win95 shell

5. Shell Folder question

6. Shell Namespace and Virutal Folders future.

7. How to open the folder in the default shell namespace

8. how can i get the list of all files/folders in a given folder

9. Finding & copying files in folder/sub folders

10. Adding files and folders to a project in the File View

11. Adding files and folders to a project in the file View of a Workspace

12. File selector which picks file and folders

 

 
Powered by phpBB® Forum Software