kurotsuke wrote:
Thanks. Can you give me an hint on using the ExtractIcon to extract
the retrieve icon? How can I draw it on a PictureBox. Thanks again.
Andrea
[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
private static extern int PickIconDlg(IntPtr hwndOwner,
System.Text.StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);
[DllImport("shell32.dll", CharSet = CharSet.Auto, CallingConvention =
CallingConvention.Winapi)]
public static extern IntPtr ExtractIcon(IntPtr hInstance, string
strFileName, uint uiIconIndex);
private void button1_Click(object sender, System.EventArgs e)
{
string iconfile;
int iconindex = 2;
int retval;
System.Text.StringBuilder sb;
iconfile = Environment.GetFolderPath(Environment.SpecialFolde r.System);
iconfile = iconfile + @"\shell32.dll";
sb = new System.Text.StringBuilder(iconfile, 500);
retval = PickIconDlg(this.Handle, sb, sb.Capacity, ref iconindex);
iconfile = sb.ToString();
Graphics g = pictureBox1.CreateGraphics();
g.DrawIconUnstretched(extractIcon(iconfile, iconindex), new
Rectangle(0, 0, 50, 50));
}
public static Icon extractIcon(string strPath, int nIndex)
{
Icon icon = null;
IntPtr hIcon = ExtractIcon(IntPtr.Zero, strPath, (uint)nIndex);
if (IntPtr.Zero != hIcon)
{
icon = Icon.FromHandle(hIcon);
}
return icon;
}
Cheers
Arne Janning