Go Back   CodeCall Programming Forum > Software Development > Tutorials > VB Tutorials
Register Blogs Search Today's Posts Mark Forums Read

VB Tutorials Visual Basic Tutorials and Code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-27-2009, 07:27 PM
Vswe's Avatar
Code Slinger
 
Join Date: Apr 2009
Location: Uppsala, Sweden
Age: 16
Posts: 8,536
Vswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond repute
Send a message via MSN to Vswe Send a message via Skype™ to Vswe
Extracting Icon from .exe

In this tutorial I will show you how to easily extract the Icons from a .exe file with VB.NET.






First we need to add this, OBSERVE that this is in the Class, not outside, this is not an import.

Code:
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer
This is what we use to get the handle from the icons so we can create the icons.





Create a new function:

Code:
    Private Function ReturnIcon(ByVal Path As String, ByVal Index As Integer, Optional ByVal small As Boolean = False) As Icon
        Dim bigIcon As Integer
        Dim smallIcon As Integer
Path is the path where the .exe is on your computer, Index is which of the exe file's icons we want starting at 0, we will create the program so if it fail to get the wanted icon it will try to get the icon at index 0 instead. Small is optional and will make the function return the small version of the icon instead. bigIcon and smallIcon is not really the icons, they are integers and will be used to create the Icon we want to return.







Try to extract icon with the right path and index:


Code:
ExtractIcon(Path, Index, bigIcon, smallIcon, 1)

If this worked, bigIcon and smallIcon have now changed in value.





If it didn't work it's still 0, and if that's the case:

Code:
        If bigIcon = 0 Then
            ExtractIcon(Path, 0, bigIcon, smallIcon, 1)
        End If
...try to get the icon at index 0.






If one of the above thing worked we can use one of the integers to get the icon we want, else return nothing:

Code:
        If bigIcon <> 0 Then
            If small = False Then
                Return Icon.FromHandle(bigIcon)
            Else
                Return Icon.FromHandle(smallIcon)
            End If
        Else
            Return Nothing
        End If
Here it creates an icon from handle with the bigIcon integer or the smallIcon integer. The Icon created is returned as the function's value.



Then end the function:

Code:
    End Function




And there we go, here's an example how to use it, observe that on error will occur if the function returns nothing:

Code:
    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.BackgroundImage = ReturnIcon("C:\Program Files\Internet Explorer\iexplore.exe", 0).ToBitmap
    End Sub
Here I just add the icon to the background of the mainform just for test. Remember if you want to use the icons in a picturebox or something like that add .ToBitmap at the end as shown above.





I'm sure you can find this usefully
__________________
My CC Blog | My Website |Periodic table | Pm me | Ask me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-27-2009, 08:29 PM
Jordan's Avatar
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Posts: 24,556
Jordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to allJordan is a name known to all
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan Send a message via Yahoo to Jordan
Re: Extracting Icon from .exe

Very cool tutorial! +rep.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-30-2009, 11:29 AM
MathX's Avatar
Guru
 
Join Date: Oct 2008
Location: Kosovo
Age: 19
Posts: 3,994
MathX has a spectacular aura aboutMathX has a spectacular aura about
Send a message via MSN to MathX
Re: Extracting Icon from .exe

+rep
__________________
My Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-08-2009, 09:54 PM
Programming Professional
 
Join Date: Apr 2006
Posts: 310
Ronin is on a distinguished road
Re: Extracting Icon from .exe

Would this be hard to convert to C#?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-09-2009, 12:11 PM
Vswe's Avatar
Code Slinger
 
Join Date: Apr 2009
Location: Uppsala, Sweden
Age: 16
Posts: 8,536
Vswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond reputeVswe has a reputation beyond repute
Send a message via MSN to Vswe Send a message via Skype™ to Vswe
Re: Extracting Icon from .exe

I don't know how to convert this:

Code:
Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Integer, ByRef phiconLarge As Integer, ByRef phiconSmall As Integer, ByVal nIcons As Integer) As Integer
But the rest would look like this:




Code:
  1. private Icon ReturnIcon(string Path, int Index, bool small)
  2. {
  3. int bigIcon = 0;
  4. int smallIcon = 0;
  5. ExtractIcon(Path, Index, bigIcon, smallIcon, 1);
  6. if (bigIcon == 0) {
  7. ExtractIcon(Path, 0, bigIcon, smallIcon, 1);
  8. }
  9. if (bigIcon != 0) {
  10. if (small == false) {
  11. return Icon.FromHandle(bigIcon);
  12. }
  13. else {
  14. return Icon.FromHandle(smallIcon);
  15. }
  16. }
  17. else {
  18. return null;
  19. }
  20. }
__________________
My CC Blog | My Website |Periodic table | Pm me | Ask me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-14-2009, 11:58 AM
Newbie
 
Join Date: Aug 2009
Posts: 24
Tuve2 is an unknown quantity at this point
Re: Extracting Icon from .exe

nice tutorial!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-22-2009, 04:30 PM
mendim.'s Avatar
Guru
 
Join Date: Nov 2008
Location: Kosovo.
Posts: 2,393
mendim. is a jewel in the roughmendim. is a jewel in the roughmendim. is a jewel in the roughmendim. is a jewel in the rough
Send a message via MSN to mendim.
Re: Extracting Icon from .exe

Very Neat Tutorial .
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I make the icon [image] background transparent on all Windows OS? Panarchy C and C++ 1 04-26-2009 08:27 PM
interface for .exe file runjun Software Development Tools 2 11-20-2008 04:15 PM
icon help Siten0308 C# Programming 6 10-29-2008 05:23 PM
XP Transparent Icon Text TcM Computer Software/OS 2 01-29-2008 04:24 AM
Change the default EXE Icon dirkfirst C# Programming 3 10-03-2006 07:10 PM


All times are GMT -5. The time now is 08:20 AM.


vBulletin v3.8.0 ©2010, Jelsoft Enterprises Ltd.


no new posts

LinkBacks Enabled by vBSEO 3.1.0