Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a .exe file with some icon (which represents the file). Could you please tell me how to extract that icon and display in a picturebox?

Your help would be highly appreciated! Thanks!
Posted
Comments
Sergey Alexandrovich Kryukov 2-Oct-12 21:07pm    
I'm curious why?
--SA

It the icon is there, and if you have Visual Studio, you can load .exe using [Main menu] => Files => Open… => File. If will open a kind of resource viewer to show the resources embedded in the executable module.

However, what you want to do is somewhat suspicious. Why? Just want to remind you that a resource could be a subject of the author's intellectual property protected by the law. Also, even though an icon can be shown in a PictureBox, it usually makes no sense, as the icons are designed for different purposes; an icon contains several images of standard sizes in one file, so the OS uses different images in different situations. With picture boxes, you don't use it. Icons are only uses as application icon and system window icons. For picture boxes, you might need to convert an icon into a bitmap. Besides, there are many situations where a picture box is used but actually useless — you don't need this control to show an image in any control.

[EDIT]

I'm sorry if it was not obvious how to retrieve the resource. Here is just the example.

I located the file "c:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSOXMLED.EXE" and loaded it in Visual Studio using main menu as shown above. In the window created as a result, I can see a tree view with the first node "Icon" and its child node "IDI_APP_ICON". Having this icon selected, I activate a context menu and choose "Export". That's it.

—SA
 
Share this answer
 
v4
Comments
supernorb 3-Oct-12 11:20am    
Anyway I still want to use PictureBox to show any image in my Temporary projects, just for convenience. After asking this question, I tried searching somewhere else in the Internet and I found some solutions, some of them was posted in CodeProject. There are at least 3 ways, the first is very simple with using the static method ExtractAssociatedIcon of the class Icon, the other two ones use Win32 API (ExtractIconEx and SHGetFileInfo, both in Shell32.dll). Converting from Icon to Bitmap is so simple with ToBitmap() method. About the intellectual property, I don't think they want to protect their application icons from people because if the 'stealers' want they can search for those in the internet easily with high quality images not only icons of 32x32. And the most suitable case you may want to extract application icons is for example when you create an application managing a list of your favorite applications and you want to place a representative icon before the application name in each entry. Thanks!
Sergey Alexandrovich Kryukov 3-Oct-12 12:16pm    
OK, this is up to you, after all.
Did I answer your question on how to extract your icon? Please try it and then accept this answer (green button), -- thanks.
--SA
supernorb 8-Oct-12 13:27pm    
Sorry for the late reply (my network had some trouble). You didn't really point out how to extract icon in an .exe file. And in fact I've found the solutions myself as I said in the last comment. I wish there were 2 accept buttons, a one is for those who deserve it with their correct and helpful answers and the other is for those who want it. Then I would click on the second for you. If you update the answer so that I see how helpful it is, I'll click on the accept button! Thanks
Sergey Alexandrovich Kryukov 8-Oct-12 13:53pm    
I though it was more then enough. OK, if you still need to "point out" this simple thing, please see the updated answer, after [EDIT].
--SA
supernorb 8-Oct-12 14:00pm    
I don't see any code to do, are you extracting icon at design time? That's not I want. What I want is simply a Browse button to select a .exe file and then show the extracted icon of that file on the form! Thanks!
Just use the LoadIcon()[^] function; although as this is C# you may need to use P/Invoke[^] to get it. Some other suggestions here[^].
 
Share this answer
 
Comments
supernorb 8-Oct-12 15:13pm    
Thanks for the another approach using LoadIcon, it's really helpful! My vote of 5 and also a click on Accept Solution.
Sergey Alexandrovich Kryukov 8-Oct-12 15:58pm    
My 5. Somehow I did not understand that OP needs do to it programmatically. It also involves loading the executable image to get an instance.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900