Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get large icon from file extension

There are several places that talk about how to get an icon from a file extension such as this one and this other one. After several hours of playing around with this kind of projects I have managed to build something like:

private void addButton_Click(object sender, System.EventArgs e)
    {           
        System.Drawing.Icon temp = IconReader.GetFileIcon(".cs", IconReader.IconSize.Large, false);
        pictureBox1.Image = temp.ToBitmap();
    }

the execution of that button gets me:

enter image description here

but I am trying to actually get the large icon. Note how the icons on windows are much bigger:

enter image description here

How could I get that icon instead of the smaller one. I have spend so much time changing the other programs. Moreover I will like to make it work with wpf and most of the examples are with windows forms. I would appreciate if I can get an example of how to extract a files icon instead of modifying and entire project. If that is not possible that would still be very helpful and I will appreciate. It's just that I am not that good of a programmer and it took me a lot of time to modify the other examples.

like image 493
Tono Nam Avatar asked Jun 22 '11 02:06

Tono Nam


2 Answers

here's a solution http://www.codeproject.com/KB/WPF/filetoiconconverter.aspx

like image 75
Code0987 Avatar answered Oct 01 '22 14:10

Code0987


The code you're referencing only uses 2 sizes:

public const uint SHGFI_LARGEICON = 0x000000000;     // get large icon
public const uint SHGFI_SMALLICON = 0x000000001;     // get small icon

to get the extra_large size, you need to add your own define (and add another enum for calling functions):

public const uint SHGFI_EXTRALARGEICON = 0x000000002;     // get extra large icon

or if you just want a quick fix, replace 0x000000000 with 0x000000002 in the original large definition.

Here are all icon sizes: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762185%28v=vs.85%29.aspx

like image 20
Eternal21 Avatar answered Oct 01 '22 12:10

Eternal21