modtheplanet Posted June 26, 2004 Posted June 26, 2004 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 Quote
*Experts* DiverDan Posted June 26, 2004 *Experts* Posted June 26, 2004 You should be able to use the DrawImage method with the icon on a new bitmap. Then set Me.PictureBox1.Image = "new bitmap". Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
modtheplanet Posted June 26, 2004 Author Posted June 26, 2004 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.