Hello all i want to know how to capture the icon of a file or folder , or at least create shortcut icon for it , and then use it in my application thx all:)
let me tell u what i want to do , i want to drag files or folders from windows explorer and drop them in my windows forms listview control then create shortcuts for them in my list view so user can double click in the item in my listview to open these files or folders , i had did all the work except the icons of the files or folders
Capture Icons
clark k
Brian Leach
truetype
I think I understand now, you want to find what is the icon of a file, like for msword.exe, you want to get the Word Icon
if so, check out my articale:
http://www.codeproject.com/cs/miscctrl/FilesListBox.aspand look at the IconExtractor util class.
Scale_Oven_Stove
Filipe Janela
Check out this link:
http://www.codeproject.com/csharp/imagecapture.asp
Astrov
Ok,so this is the link you need:
http://www.codeproject.com/cs/miscctrl/FilesListBox.asp
This is the class you need:
/// <summary> /// Util class to extract icons from files or directories. /// </summary> class IconExtractor{
[
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);}
/// <summary> /// Gets the icon asotiated with the filename. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public static Icon GetFileIcon(string fileName, IconSize _iconSize){
System.Drawing.Icon myIcon =
null; try{
IntPtr hImgSmall; //the handle to the system image listSHFILEINFO shinfo =
new SHFILEINFO(); //Use this to get the small IconhImgSmall = Win32.SHGetFileInfo(fileName, 0,
ref shinfo,(
uint)Marshal.SizeOf(shinfo),Win32.SHGFI_ICON |
(_iconSize == IconSize.Small Win32.SHGFI_SMALLICON : Win32.SHGFI_LARGEICON) );
//The icon is returned in the hIcon member of the shinfo //structmyIcon =
System.Drawing.Icon.FromHandle(shinfo.hIcon);
}
catch{
return null;}
return myIcon;}
}
/// <summary> /// Specifies the icon size (16 or 32) /// </summary> public enum IconSize{
/// <summary> /// 16X16 icon /// </summary>Small,
/// <summary> /// 32X32 icon /// </summary>Large
}
Call :
Icon fileIcon = IconExtractor.GetFileIcon(fullFileName, _IconSize.Small);
hegel
Many thx, it works and i did most of the work using it
and this article was very helpful
Seclymer
thx eli for your quick response and your interest
but for sorry! the topic that u sent to me not covers my question
any way the article that u sent to was a very good one
and i will try to find an answer to my question and if i found it i will tell u
TheBadmojo