Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

the IconEx.GetAssociatedIconLarge returns a icon object

 

 

i need to take its icon object and display it in a picturebox, how do you do that?

 

then i need to save the icon to VB6code : appath & "\icons" & icon

 

 

this is what i have minus the saving which i cant seem to grasp either.

 

               Dim largeIcon As Icon = IconEx.GetAssociatedIconLarge("C:\Program Files\AIM\aim.exe")
       'returns a icon object
       Dim myIconImage As New Bitmap(largeIcon.Width, largeIcon.Height)
       myIconImage = New Bitmap(largeIcon.Height, largeIcon.Width)
       myIconImage = largeIcon.ToBitmap
       Me.PictureBox1.Image = myIconImage

  • *Experts*
Posted
You should be able to use the DrawImage method with the icon on a new bitmap. Then set Me.PictureBox1.Image = "new bitmap".

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted

my code breaks on this line:

 

myIconImage = New Bitmap(largeIcon.Height, largeIcon.Width)

 

 

give the error:

 

An unhandled exception of type 'System.NullReferenceException' occured in blah.exe

 

Additional Information: Object Reference not set to an instance of an object

 

here is the module code for IconEx:

 

Public Class IconEx
#Region " API "
   Private Const MAX_PATH = 260
   Private Const SHGFI_LARGEICON = &H0
   Private Const SHGFI_SMALLICON = &H1
   Private Const SHGFI_ICON = &H100

   Private Structure SHFILEINFO
       Dim hIcon As IntPtr
       Dim iIcon As Integer
       Dim dwAttributes As Integer
       <VBFixedString(MAX_PATH)> Dim szDisplayName As String
       <VBFixedString(80)> Dim szTypeName As String
   End Structure

   Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" ( _
   ByVal pszPath As String, _
   ByVal dwFileAttributes As Integer, _
   ByRef psfi As SHFILEINFO, _
   ByVal cbFileInfo As Integer, _
   ByVal uFlags As Integer) As Integer
#End Region

   Private Shared Function _geticon(ByVal file As String, ByVal size As Integer) As Icon
       Dim fileIcon As Icon
       Dim m As System.Runtime.InteropServices.Marshal
       Dim shinfo As SHFILEINFO

       'This gets the icon out of the specified file and puts it into the shinfo struct, and
       'out into an Icon object.
       If SHGetFileInfo(file, 0, shinfo, m.SizeOf(shinfo), SHGFI_ICON Or size) Then
           fileIcon = Icon.FromHandle(shinfo.hIcon)
           Return fileIcon
       End If
   End Function

   'Retrieves the 16x16 icon for a file
   Public Shared Function GetAssociatedIconSmall(ByVal file As String) As Icon
       If Not System.IO.File.Exists(file) Then
           Throw New IO.FileNotFoundException("The specified file was not found", file)
       Else
           Return IconEx._geticon(file, SHGFI_SMALLICON)
       End If
   End Function

   'Retrieves the 32x32 icon for a file
   Public Shared Function GetAssociatedIconLarge(ByVal file As String) As Icon
       If Not System.IO.File.Exists(file) Then
           Throw New IO.FileNotFoundException("The specified file was not found", file)
       Else
           IconEx._geticon(file, SHGFI_LARGEICON)
       End If
   End Function
End Class

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...