Suraj Rai

Suraj Rai

  • NA
  • 111
  • 0

Getting Folders Icon Image...Unable to take large Icons...

Feb 1 2007 2:12 AM

Hi,

I am using SHGetFileInfo Function to Get the Icons That Are Associated with Files and
folders.

I got the code from an article . http://www.codeguru.com/Csharp/Csharp/cs_misc/icons/article.php/c4261/

The code goes like this :

At the beggining of Namespace :

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
  public IntPtr hIcon;
  public IntPtr iIcon;
  public uint dwAttributes;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
  public string szDisplayName;
  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
  public string szTypeName;
};

class Win32
{
  public const uint SHGFI_ICON = 0x100;
  public const uint SHGFI_LARGEICON = 0x0;    // 'Large icon
  public const uint SHGFI_SMALLICON = 0x1;    // 'Small icon

  [DllImport("shell32.dll")]
  public static extern IntPtr SHGetFileInfo(string pszPath,
                              uint dwFileAttributes,
                              ref SHFILEINFO psfi,
                              uint cbSizeFileInfo,
                              uint uFlags);
}


in button click :

             IntPtr hImgSmall;
            IntPtr hImgLarge;
            YuntaaControls.SHFILEINFO shinfo = new YuntaaControls.SHFILEINFO();
            YuntaaControls.SHFILEINFO Lginfo = new YuntaaControls.SHFILEINFO();


            hImgSmall = YuntaaControls.Win32.SHGetFileInfo(LocalPath, 0, ref shinfo,
                                       (uint)Marshal.SizeOf(shinfo),
                                        YuntaaControls.Win32.SHGFI_ICON |
                                        YuntaaControls.Win32.SHGFI_LARGEICON);

            // For large Icon
            //hImgLarge = YuntaaControls.Win32.SHGetFileInfo(LocalPath, 0, ref shinfo,
            //                           (uint)Marshal.SizeOf(shinfo),
            //                            YuntaaControls.Win32.SHGFI_ICON |
            //                            YuntaaControls.Win32.SHGFI_LARGEICON);


            System.Drawing.Icon myIcon =
                   System.Drawing.Icon.FromHandle(shinfo.hIcon);

            //System.Drawing.Icon myLgIcon =
            //      System.Drawing.Icon.FromHandle(shinfo.hIcon);

           
          imgListYuntaaFileBrowse.Images.Add(myIcon);


Every thing goin fine. The only problem is that i am not been able to take
the bigger Icon. the Icons are coming very small.

What I want is that when we click "Save As" we get one Dialog box from where
we can browse and save our file.

If we see the left side of that dialogbox
we see some big icons for "Desktop","my recent documents", "My Computer" n so on.

how to get thouse big icons. Is there any way that we can the desired size.
Something like we can mention the icon size and we will get that.

If anyone has any Idea. Do help.

Thanks

 

          

 


Answers (1)