Re: Icon transparency after Serialization
- From: "Mike_IntermediateVB" <MikeIntermediateVB@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 16 Oct 2005 17:55:02 -0700
"Michael Phillips, Jr." wrote:
> How are you serializing the HICON that is returned?
Thanks for reply I will spend a bit of time trying to understand the API,
below is a sample of the way I am capturing the Icons.
I create an Obj and add the ResourceIconCollection to it. Then add icons by
Object.ResourceIconCollection.AddIcon(IconPath). Then serialise the whole obj
using....
Private Function SerilaiseObject() As Byte()
Dim serializer As New BinaryFormatter
Dim objData As New MemoryStream
serializer.Serialize(objData, obj)
objData.Seek(0, 0)
Return objData.ToArray()
End Function
then I compress the byte array and save it to the database.
Code..............
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'--List of ICONs
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<Serializable()> Public Class ResourceIconCollection
Public IconList As New ArrayList
Public Function AddIcon(ByVal strPath)
If IconList.Count = 0 Then
Dim newIcon As New SingleIcon(strPath)
IconList.Add(newIcon)
Else
'--Check if Icon exsists
Dim Currenticon As SingleIcon
Dim FileExt As String =
LCase(System.IO.Path.GetExtension(strPath))
For Each Currenticon In IconList
If FileExt = Currenticon.Key Then
'--Icon extension has beem Found
Exit Function
End If
Next
'--No Exsisting Icons for this Extension found, so Add a new one
Dim newIcon As New SingleIcon(strPath)
IconList.Add(newIcon)
End If
End Function
End Class
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'--Single ICON
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<Serializable()> Public Class SingleIcon
Public icon As System.Drawing.Icon
Public Key As String
Public Sub New()
End Sub
Public Sub New(ByVal strPath As String)
icon = Icons.GetIcon(strPath)
Key = LCase(System.IO.Path.GetExtension(strPath))
End Sub
End Class
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'--Get ICON
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Imports System.Runtime.InteropServices
Public Class Icons
Private Structure SHFILEINFO
Public hIcon As IntPtr ' : icon
Public iIcon As Integer ' : icondex
Public dwAttributes As Integer ' : SFGAO_ flags
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
Public szDisplayName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
Public szTypeName As String
End Structure
Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
(ByVal pszPath As String, _
ByVal dwFileAttributes As Integer, _
ByRef psfi As SHFILEINFO, _
ByVal cbFileInfo As Integer, _
ByVal uFlags As Integer) As IntPtr
Private Const SHGFI_ICON = &H100
Private Const SHGFI_SMALLICON = &H1
Private Const SHGFI_LARGEICON = &H0 ' Large icon
Private nIndex = 0
Public Shared Function GetIcon(ByVal strPathName As String) As
System.Drawing.Icon
'--Get Icon
Dim hImgSmall As IntPtr
Dim shinfo As SHFILEINFO
shinfo = New SHFILEINFO
shinfo.szDisplayName = New String(Chr(0), 260)
shinfo.szTypeName = New String(Chr(0), 80)
'Use this to get the small icon.
hImgSmall = SHGetFileInfo(strPathName, 0, shinfo, _
Marshal.SizeOf(shinfo), _
SHGFI_ICON Or SHGFI_SMALLICON)
Dim myIcon As System.Drawing.Icon
myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon)
Return myIcon
End Function
End Class
.
- Follow-Ups:
- Re: Icon transparency after Serialization
- From: Michael Phillips, Jr.
- Re: Icon transparency after Serialization
- References:
- Re: Icon transparency after Serialization
- From: Michael Phillips, Jr.
- Re: Icon transparency after Serialization
- From: Mike_IntermediateVB
- Re: Icon transparency after Serialization
- From: Michael Phillips, Jr.
- Re: Icon transparency after Serialization
- Prev by Date: Re: Icon transparency after Serialization
- Next by Date: Re: StretchDIBits in managed
- Previous by thread: Re: Icon transparency after Serialization
- Next by thread: Re: Icon transparency after Serialization
- Index(es):
Relevant Pages
|