Home All Groups Group Topic Archive Search About
Author
18 Apr 2007 11:37 AM
JB

I am using SHGetFileInfo to get the list of icons for a bunch of
files, and taking those icons and putting them in an ImageList.  The
ImageList is then being used with a ListView control to display the
list of files and their associated icons.

Unfortunately the alpha transparencies appear as black in the icons.
To resolve this I tried (as per the microsoft article:
http://msdn2.microsoft.com/en-us/library/aa289524(VS.71).aspx) to add
a manifest to the exe file, I also changed the colordepth of the
ImageList to: ColorDepth.Depth32Bit.

The icons still have a black border.

I am using VS2005, .NET framework 2.0 on an XP machine.

The manifest I used is below.

Can anyone suggest anything else I can do to get the icons without the
black border?

Thanks.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
   version="1.0.0.0"
   processorArchitecture="X86"
   name="Microsoft.Winweb.WindowsApplication6"
   type="win32"
/>
<description>.NET control deployment tool</description>
<dependency>
   <dependentAssembly>
     <assemblyIdentity
       type="win32"
       name="Microsoft.Windows.Common-Controls"
       version="6.0.0.0"
       processorArchitecture="X86"
       publicKeyToken="6595b64144ccf1df"
       language="*"
     />
   </dependentAssembly>
</dependency>
</assembly>

Author
18 Apr 2007 1:19 PM
Jeff Gaines
On 18/04/2007 in message
<1176896226.224895.320***@b58g2000hsg.googlegroups.com> JB wrote:

>I am using SHGetFileInfo to get the list of icons for a bunch of
>files, and taking those icons and putting them in an ImageList.  The
>ImageList is then being used with a ListView control to display the
>list of files and their associated icons.

You can associate the system images directly with a ListView, I use:

protected override void OnHandleCreated(EventArgs e)
        {
            //    Need a handle to set the image list
            base.OnHandleCreated(e);
            cCommon.SetSmallSystemImageList(this);
            cCommon.SetLargeSystemImageList(this);
    }

public static int SetLargeSystemImageList(ListView lv)
        {
            const int LVM_FIRST = 0x1000;
            const int LVM_SETIMAGELIST = (LVM_FIRST + 3);
            const int LVSIL_NORMAL = 0;

            IntPtr ipLargeSystemImageList = GetLargeSystemImageList();

            // Associate the System image list with the ListView
            return SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL,
ipLargeSystemImageList);
        }

        public static int SetSmallSystemImageList(ListView lv)
        {
            const int LVM_FIRST = 0x1000;
            const int LVM_SETIMAGELIST = (LVM_FIRST + 3);
            const int LVSIL_SMALL = 1;

            IntPtr ipSmallSystemImageList = GetSmallSystemImageList();

            // Associate the System image list with the ListView
            return SendMessage(lv.Handle, LVM_SETIMAGELIST, LVSIL_SMALL,
ipSmallSystemImageList);
        }


public static IntPtr GetLargeSystemImageList()
        {
            // Get System Image List
            const int SHGFI_SYSICONINDEX = 0x000004000;
            const int SHGFI_LARGEICON = 0x000000000;
            const int SHGFI_USEFILEATTRIBUTES = 0x000000010;

            uint uFlags = SHGFI_SYSICONINDEX | SHGFI_LARGEICON |
SHGFI_USEFILEATTRIBUTES;

            SHFILEINFO shfi = new SHFILEINFO();

            IntPtr ipLargeSystemImageList = SHGetFileInfo(@"c:\Temp\*.txt", 0, out
shfi, Marshal.SizeOf(typeof(SHFILEINFO)), uFlags);

            if (shfi.hIcon != IntPtr.Zero)
                DestroyIcon(shfi.hIcon);

            return ipLargeSystemImageList;
        }

public static IntPtr GetSmallSystemImageList()
        {
            // Get System Image List
            const int SHGFI_SYSICONINDEX = 0x000004000;
            const int SHGFI_SMALLICON = 0x000000001;
            const int SHGFI_USEFILEATTRIBUTES = 0x000000010;

            uint uFlags = SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
SHGFI_USEFILEATTRIBUTES;

            SHFILEINFO shfi = new SHFILEINFO();

            IntPtr ipSmallSystemImageList = SHGetFileInfo(@"c:\Temp\*.txt", 0, out
shfi, Marshal.SizeOf(typeof(SHFILEINFO)), uFlags);

            if (shfi.hIcon != IntPtr.Zero)
                DestroyIcon(shfi.hIcon);

            return ipSmallSystemImageList;
        }

I then use SHGetFileInfo to get the icon index and use:
ListViewItem lv = new ListViewItem(FileName, intIcon);

Using this method the icons display properly.

--
Jeff Gaines
Are all your drivers up to date? click for free checkup

Author
18 Apr 2007 6:58 PM
JB
Works like a charm.

Thanks.

Bookmark and Share