Results 1 to 19 of 19

Thread: Help with Flickering Picture Box (Tricky)

  1. #1

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Help with Flickering Picture Box (Tricky)

    I have loaded a series of gifs into an imagelist. I have a timer which shows each image inturn to simulate an animated gif.

    Now this works great, except it flickers, so I changed my code to:

    Me.Picture1.PaintPicture Me.ImageList1.ListImages(counter).Picture, 0, 0

    This works fine, no flicker, but the background changes from transparent to black!


    How can I remove the flicker and keep the background transparent??????
    Last edited by Nucleus; Mar 13th, 2002 at 02:53 AM.

  2. #2
    gaffa
    Guest
    You might want to use DrawIconNormal to draw the image from the listview - it seems to honour the transparent colour OK. Just pull the picture form the image usin ImageList.ExtractIcon, or any other methods you choose, and plonk it onto the picture box.

    - gaffa

  3. #3

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Gaffa what do you mean by DrawIconNormal, is it an API?

  4. #4
    gaffa
    Guest
    Yeah, it's API, 'cept it's not called DrawIconNormal (that's my wrapper function). It's DrawIconEx:

    VB Code:
    1. ' Standard GDI draw icon function:
    2. Public Const DI_MASK = &H1
    3. Public Const DI_IMAGE = &H2
    4. Public Const DI_NORMAL = &H3
    5. Public Const DI_COMPAT = &H4
    6. Public Const DI_DEFAULTSIZE = &H8
    7.  
    8. Public Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, _
    9.                     ByVal xLeft As Long, _
    10.                     ByVal yTop As Long, _
    11.                     ByVal hIcon As Long, _
    12.                     ByVal cxWidth As Long, _
    13.                     ByVal cyWidth As Long, _
    14.                     ByVal istepIfAniCur As Long, _
    15.                     ByVal hbrFlickerFreeDraw As Long, _
    16.                     ByVal diFlags As Long) As Long
    17.  
    18. 'Some sample usage code
    19.  
    20.     Dim lobjPic as StdPicture
    21.     Dim lhIcon as Long
    22.     Set lobjPic = gobjImageList.ListImages(1).ExtractIcon
    23.     lhIcon = lobjPic.Handle
    24.     DrawIconNormal mhBufferDC,  300, _
    25.                                100, lhIcon, 16, 16
    26.     'Destroy the icon to release the memory
    27.     DestroyIcon lhIcon

    That might help.

    - gaffa

  5. #5
    gaffa
    Guest
    Oh, yeah, use the DI_ constants for the last parameter of the DrawIconEx. I know I was passing in stuff to DrawIconNormal, so here's the code for that:
    VB Code:
    1. Public Sub DrawIconNormal(phDestDC As Long, pLeft As Long, pTop As Long, _
    2.                           phIcon As Long, pIconWidth As Long, pIconHeight As Long)
    3.  
    4.     'Draws the icon
    5.     DrawIconEx phDestDC, pLeft, pTop, phIcon, pIconWidth, pIconHeight, 0, 0, DI_NORMAL
    6.    
    7. End Sub

    - gaffa

  6. #6

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    I couldn't get it to work Gaffa, I have attached a project with all the files..... could you take a squiz at it?

  7. #7
    gaffa
    Guest
    Playing with it now. Got some strange behaviour...

    - gaffa

  8. #8

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Thanks

  9. #9
    gaffa
    Guest
    It's being a pain in the date...

    I'm changed the code to draw to a memory DC, which works, but I can't get rid of the bloody background...

    Currenly trying to use some of the ImageList API calls, but I'm not sure if they work on XP (I know for sure that at least one of the doesn't)

    - gaffa

  10. #10
    gaffa
    Guest
    OK, got it working....

    But there's a caveat (two actually).

    On my machine (and I'm the first to admit my stupid machine isn't being particullary stable at the moment), it tends to crash VB one in every two tries. Sometimes needs a break put in, then once you've hit that it works...

    Second ly, the only way I could mask it properly (and you can create proper masks, but I'm slack), is I used TranaparentBlt from the msimg32.dll file

    - gaffa

  11. #11

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Thanks for the big effort Gaffa , but when I tested it on Windows 2000, the background turned out Red .... but the good news is no flicker

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    TransparentBLT = Memory Leaks, so thats probably why VB is crashing.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  13. #13
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Why don't you just use the "Draw()" method of the ListImage item?, i.e.
    VB Code:
    1. ImageList1.ListImages(lFrame).Draw hDC, 0, 0, imlTransparent

  14. #14

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Originally posted by Aaron Young
    Why don't you just use the "Draw()" method of the ListImage item?, i.e.
    VB Code:
    1. ImageList1.ListImages(lFrame).Draw hDC, 0, 0, imlTransparent
    I tried this Aaron:

    VB Code:
    1. Private Sub Timer1_Timer()
    2.     Static counter As Long
    3.    
    4.     If counter = 9 Then
    5.         counter = 0
    6.     End If
    7.  
    8.     If counter = 0 Then counter = 1
    9.    
    10.         Debug.Print "now" & counter
    11.         ImageList1.ListImages(counter).Draw Picture1.hdc, 0, 0, imlTransparent
    12.    
    13.     counter = counter + 1
    14. End Sub

    but I nothing displays in the picture box at all, it looks like the whole picture is painted on to the pic box transparently

  15. #15
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If the AutoRedraw Property of the Picturebox is set to True you wouldn't see anything, either set it to False or update the Picture property with the Image property.

  16. #16

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Aaron.... looks like I still get a flicker and the background is black

    I have attached the project to demo, I might have missed something...

    btw I am using NT at the moment... but also use 2000.

  17. #17
    gaffa
    Guest
    I've never used the TransparentBlt call before, so I didn't realise it leaked memory. It's crap anyway - you really don't want to have to distribute the extra DLL.

    In my defence for being dumb, I wrote that at 11:00pm having been in front of the computer for the previous 14 hours, so I was a bit tired.

    The red background you can change to whatever you want - the DrawFilledRect call just fills the picture box with red so I could make sure that it was masking properly.

    I had a play with the draw method, and that works pretty nicely. No idea why I didn't use that - I feel a bit sheepish...

    Actually, I think I did, but forgot to change the mask colour to black...

    Oh well, you live and learn.

    - gaffa

  18. #18
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    This works for me:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     ' Set the MaskColor to Black, because you're using Transparent GIF's
    5.     ImageList1.MaskColor = vbBlack
    6. End Sub
    7.  
    8. Private Sub Timer1_Timer()
    9.     Static lFrame As Long
    10.    
    11.     Picture1.AutoRedraw = True
    12.     Picture1.Cls ' Or Redraw BackGround
    13.     ImageList1.ListImages(lFrame + 1).Draw Picture1.hDC, 0, 0, imlTransparent
    14.     Picture1.AutoRedraw = False
    15.    
    16.     lFrame = (lFrame + 1) Mod ImageList1.ListImages.Count
    17. End Sub

  19. #19

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    That works perfectly Aaron, thanks

    Just wondering what API is being called via the draw method and to set the mask colour?

    Thanks Gaffa for the effort too!

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