Results 1 to 7 of 7

Thread: Fading An Icon Image

  1. #1

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Question Fading An Icon Image

    I'm using the SHGetFileInfo API get a handle to the 16 x 16 file icon, which all works fine.

    How can I fade the icon image, like the Windows Explorer fades hidden files in Windows 2000.

    I'm not using the ListView control so I can't use the Ghosted property, and I've already asked the API people and got no joy.

    There must be a way of fading an icon image.


    Help


    Thanks in advance

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Well you could blend it 50/50 with a blank icon, or do a loop over the pixels of the icon to change the pixel colour to halfway between what it is and white...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185
    Have you got any examples please?

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This code doesnt work yet, but I'd do something long these lines :

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    4. Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
    5.  
    6. Private Sub Form_Load()
    7.     Picture1.Picture = LoadPicture("c:\a.bmp")
    8.     Me.Show
    9.     HalfFadeToWhite Picture1
    10. End Sub
    11.  
    12. Private Sub HalfFadeToWhite(destPic As PictureBox)
    13.     Dim i As Long, j As Long, col As Long
    14.     Dim colwhite As Long, colRed As Long, colGreen As Long, colBlue As Long
    15.     colwhite = RGB(255, 255, 255)
    16.     destPic.Visible = False
    17.     For i = 0 To destPic.ScaleWidth
    18.         For j = 0 To destPic.ScaleHeight
    19.             col = GetPixel(destPic.hdc, i, j)
    20.             colRed = ((col Mod 256) + 255) / 2
    21.             colGreen = ((((col And &HFF00) / 256&) Mod 256&) + 255) / 2
    22.             colBlue = (((col And &HFF0000) / 65536) + 255) / 2
    23.             SetPixel destPic.hdc, i, j, RGB(colRed, colGreen, colBlue)
    24.         Next
    25.     Next
    26.     destPic.Visible = True
    27.     destPic.Refresh
    28. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  5. #5

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Smile

    I like the idea.

    I'm doing all this in a VB Active X DLL, and I don't want to add any forms to the project.

    What is the easiest way to get a DC handle?

    Create one using the CreateDC or CreateCompatibleDC API's, or use an existing one using the GetDC API.

    If I was going to use an existing DC, which one would I use?
    Can I use the Desktop DC?

  6. #6
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Quote from MSDN :

    <start quote>
    CreateCompatibleDC
    The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.

    HDC CreateCompatibleDC(
    HDC hdc // handle to the device context
    );

    Parameters
    hdc
    Handle to an existing device context. If this handle is NULL, the function creates a memory device context compatible with the application's current screen.
    <end quote>


    So it would appear that if you pass a null as the parameter to the createcompatibledc function it'll create a new dc for you anyway.
    So try that.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  7. #7

    Thread Starter
    Addicted Member VB6Coder's Avatar
    Join Date
    Apr 2001
    Location
    Northampton, UK
    Posts
    185

    Talking

    I've just tried:

    lngDC = CreateCompatibleDC(0)

    and it works . It returns the new compatible DC handle.


    Nice one


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