Results 1 to 2 of 2

Thread: Transparent Images?

  1. #1

    Thread Starter
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Transparent Images?

    I am writing a small Asp.net App for my friends because it seems they find network based file access "too complicated". meh....

    Anyway, i figured it would be a nice touch to display the default system icons for the file type.

    (i know if i really wanted to make this simple i could create a virtual directory and enable directory browsing in IIS, but im subborn)

    This class i put together works fine but the image background isnt transparent, its black. This doesnt look to great on the page unless its black, and its not ;(


    what am i missing?

    VB Code:
    1. Public Enum IconSize
    2.         Large
    3.         Small
    4.     End Enum
    5.  
    6.     Public Class FileSytemIcon
    7.  
    8. #Region " API "
    9.         Private Structure SHFILEINFO
    10.             Public hIcon As IntPtr            ' : icon
    11.             Public iIcon As Integer           ' : icondex
    12.             Public dwAttributes As Integer    ' : SFGAO_ flags
    13.             <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
    14.             Public szDisplayName As String
    15.             <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
    16.             Public szTypeName As String
    17.         End Structure
    18.  
    19.         Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _
    20.                 (ByVal pszPath As String, _
    21.                  ByVal dwFileAttributes As Integer, _
    22.                  ByRef psfi As SHFILEINFO, _
    23.                  ByVal cbFileInfo As Integer, _
    24.                  ByVal uFlags As Integer) As IntPtr
    25.  
    26.         Private Const SHGFI_ICON = &H100
    27.         Private Const SHGFI_SMALLICON = &H1
    28.         Private Const SHGFI_LARGEICON = &H0    ' Large icon
    29.  
    30. #End Region
    31.  
    32. #Region " Properties and Member Variables "
    33.         Private m_iSmall As Icon
    34.         Private m_iLarge As Icon
    35.  
    36.         Public ReadOnly Property SmallIcon() As Icon
    37.             Get
    38.                 Return m_iSmall
    39.             End Get
    40.         End Property
    41.  
    42.         Public ReadOnly Property LargeIcon() As Icon
    43.             Get
    44.                 Return m_iLarge
    45.             End Get
    46.         End Property
    47.  
    48. #End Region
    49.  
    50. #Region " Private Methods "
    51.  
    52.         Private Sub RetriveIcons(ByVal strExtension As String)
    53.             Dim hImgSmall As IntPtr
    54.             Dim hImgLarge As IntPtr
    55.  
    56.             Dim shinfo As New SHFILEINFO
    57.  
    58.  
    59.             shinfo.szDisplayName = New String(Chr(0), 260)
    60.             shinfo.szTypeName = New String(Chr(0), 80)
    61.  
    62.  
    63.             'SmallIcon
    64.             hImgSmall = SHGetFileInfo(strExtension, 0, shinfo, _
    65.                         Marshal.SizeOf(shinfo), _
    66.                         SHGFI_ICON Or SHGFI_SMALLICON)
    67.  
    68.             m_iSmall = System.Drawing.Icon.FromHandle(shinfo.hIcon)
    69.  
    70.             'LargeIcon
    71.             hImgLarge = SHGetFileInfo(strExtension, 0, shinfo, _
    72.                         Marshal.SizeOf(shinfo), _
    73.                         SHGFI_ICON Or SHGFI_LARGEICON)
    74.  
    75.             m_iLarge = System.Drawing.Icon.FromHandle(shinfo.hIcon)
    76.  
    77.         End Sub
    78. #End Region
    79.  
    80.  
    81.         Public Sub New(ByVal Extension As String)
    82.             RetriveIcons(Extension)
    83.         End Sub
    84.  
    85.     End Class

    Sample in jpg attached (icon for .ini)
    Last edited by <ABX; Aug 22nd, 2004 at 04:19 PM.
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    pax has posted a working code for fixing transparency issues . (in this forum and I think in the CodeBank also ) .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width