???? ID: 319350 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
????? ????? C# .NET ??? ??????? ?? ??? ?????? ??? ?? ??????? ???? ?? ??? SHGetFileInfo ?????? ?? ????? ???? ????
?????? ?????? This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
?? ??? ?? ??? ???? ????? ?? ?? ?? ????? ???? ????
SHGetFileInfo ??????? ?? ??? ?????? ????? ??????? ???? ?? ??? ????? ?????
???? ??????? ?? Windows ????????? ?????Microsoft Visual Studio .NET ???? ????.. ????? ???????? ???? ??,??? ?? ????-????? ????, ?? ???? ???????????? . ???????? ????????? ????? ????? ???, ????? ????????? C# ????????? ?? ???????????????? ?????? ?? ????-????? ????, ?? ???? ???Windows ????????? ?? ??????????????? . ???????? ????? ???,GetIconSample . SHGetFileInfo ?????? ?? ????? ????Form1.cs ????? ?? ??? ??? ????? ??? ???????? ????? ???? ????
using System.Runtime.InteropServices;
??? ??? ????? ??? ??????Form1 ?? ????GetIconSample ??? ????? ???
[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);
}
??? ????? ??? ??????Form1 ???? ??? ???????? ???: ????? ???listView ???????? ?? ???, ??????? ????????, ?? ??imageList ????????? ???? ?? ??? ???????? ???????? ??? ??? listView1, button1 ?? imageList1 respectively. ?? ??? ????? ???Button1 , ??? ??? ?? ??? ??? ???????? ????? ?? ??? ???? , ?? ???? ??? ??? ????? ??? ??????button1_click ?????:
IntPtr hImgSmall; //the handle to the system image list
IntPtr hImgLarge; //the handle to the system image list
string fName; // 'the file name to get icon from
SHFILEINFO shinfo = new SHFILEINFO();
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\temp\\";
openFileDialog1.Filter = "All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true ;
listView1.SmallImageList = imageList1;
listView1.LargeImageList = imageList1;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
fName = openFileDialog1.FileName;
//Use this to get the small Icon
hImgSmall = Win32.SHGetFileInfo(fName, 0, ref shinfo,(uint)Marshal.SizeOf(shinfo),Win32.SHGFI_ICON |Win32.SHGFI_SMALLICON);
//Use this to get the large Icon
//hImgLarge = SHGetFileInfo(fName, 0,
// ref shinfo, (uint)Marshal.SizeOf(shinfo),
// Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);
//The icon is returned in the hIcon member of the shinfo struct
System.Drawing.Icon myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
imageList1.Images.Add(myIcon);
//Add file name and icon to listview
listView1.Items.Add(fName, nIndex++);
}
????????? ?? ?????????????? ?? ?????? ????: ??????? ???? ??,?????? ????? . ????????? ?? ????? ?? ??? F5 ?????.. ????? ????,???? ????? ?? ??? ???? , ?? ???? ??? ??? ???? ????? ?? ??? ????????? ????? ????? ?? ??????? ?? ??? ?? .. ????? ?? ????? ?? ?????? ?? ?? ????? ?? ??? ??? ????? ???? ??????? ????? ???????? ??? ?? ???? ?? Microsoft Visual Basic .NET ??????? ??? ???? ??????? ?? ??? Microsoft ???????? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
319340
(http://support.microsoft.com/kb/319340/
)
Visual Basic .NET ??? ??????? ?? ??? ?????? ????? ??????? ???? ?? ??? SHGetFileInfo ?????? ?? ????? ???? ????
???? ???? ???? ??: Microsoft Visual Studio .NET 2003 Professional Edition Microsoft Visual Studio .NET 2003 Enterprise Architect Microsoft Visual Studio .NET 2003 Enterprise Developer Microsoft Visual Studio .NET 2003 Academic Edition Microsoft Visual Studio .NET 2002 Professional Edition Microsoft Visual Studio .NET 2002 Enterprise Architect Microsoft Visual Studio .NET 2002 Enterprise Developer Microsoft Visual Studio .NET 2002 Academic Edition kbhowtomaster kbmt KB319350 KbMthi
???? ?????? ???????? ??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
319350
(http://support.microsoft.com/kb/319350/en-us/
)
Was this information helpful?
How much effort did you personally put forth to use this article?
Tell us why and what can we do to improve this information
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .
???? ?????? ???? ?????? ??????
??????
??? ?????? ??????? ????
???? ??????