Re: Icon transparency after Serialization



"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
.



Relevant Pages

  • Re: Run-time error ,50003 - Unexpected error
    ... VB6 supports only 16 color icons for Forms. ... Put the required icons in a resource file. ... Private Declare Function GetModuleHandle Lib "kernel32.dll" _ ... Private Const LR_DEFAULTCOLOR As Long = &H0 ...
    (microsoft.public.vb.general.discussion)
  • Re: Run-time error ,50003 - Unexpected error
    ... VB6 supports only 16 color icons for Forms. ... Put the required icons in a resource file. ... Private Declare Function GetModuleHandle Lib "kernel32.dll" _ ... Private Const LR_DEFAULTCOLOR As Long = &H0 ...
    (microsoft.public.vb.general.discussion)
  • Re: Can I have a tooltiptext with an Icon?????
    ... Private Type LINKDATA ... Dim MyData() As LINKDATA ... I also move the icons around on the form with the ...
    (microsoft.public.vb.general.discussion)
  • Re: ListView (two questions)
    ... > Q1) How to prevent moving the icons ... Private Sub Form_Load ... Private Sub ListView1_MouseMove(Button As Integer _ ...
    (microsoft.public.vb.winapi)
  • Re: ListView (two questions)
    ... > Q1) How to prevent moving the icons ... Private Sub Form_Load ... Private Sub ListView1_MouseMove(Button As Integer _ ...
    (microsoft.public.vb.controls)