|
-
Mar 12th, 2002, 07:37 PM
#1
Thread Starter
Registered User
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.
-
Mar 13th, 2002, 02:36 AM
#2
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
-
Mar 13th, 2002, 02:52 AM
#3
Thread Starter
Registered User
Gaffa what do you mean by DrawIconNormal, is it an API?
-
Mar 13th, 2002, 03:34 AM
#4
Yeah, it's API, 'cept it's not called DrawIconNormal (that's my wrapper function). It's DrawIconEx:
VB Code:
' Standard GDI draw icon function:
Public Const DI_MASK = &H1
Public Const DI_IMAGE = &H2
Public Const DI_NORMAL = &H3
Public Const DI_COMPAT = &H4
Public Const DI_DEFAULTSIZE = &H8
Public Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, _
ByVal xLeft As Long, _
ByVal yTop As Long, _
ByVal hIcon As Long, _
ByVal cxWidth As Long, _
ByVal cyWidth As Long, _
ByVal istepIfAniCur As Long, _
ByVal hbrFlickerFreeDraw As Long, _
ByVal diFlags As Long) As Long
'Some sample usage code
Dim lobjPic as StdPicture
Dim lhIcon as Long
Set lobjPic = gobjImageList.ListImages(1).ExtractIcon
lhIcon = lobjPic.Handle
DrawIconNormal mhBufferDC, 300, _
100, lhIcon, 16, 16
'Destroy the icon to release the memory
DestroyIcon lhIcon
That might help.
- gaffa
-
Mar 13th, 2002, 03:36 AM
#5
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:
Public Sub DrawIconNormal(phDestDC As Long, pLeft As Long, pTop As Long, _
phIcon As Long, pIconWidth As Long, pIconHeight As Long)
'Draws the icon
DrawIconEx phDestDC, pLeft, pTop, phIcon, pIconWidth, pIconHeight, 0, 0, DI_NORMAL
End Sub
- gaffa
-
Mar 13th, 2002, 03:58 AM
#6
Thread Starter
Registered User
I couldn't get it to work Gaffa, I have attached a project with all the files..... could you take a squiz at it?
-
Mar 13th, 2002, 04:46 AM
#7
Playing with it now. Got some strange behaviour...
- gaffa
-
Mar 13th, 2002, 05:03 AM
#8
Thread Starter
Registered User
Thanks
-
Mar 13th, 2002, 05:09 AM
#9
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
-
Mar 13th, 2002, 05:30 AM
#10
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
-
Mar 13th, 2002, 07:20 AM
#11
Thread Starter
Registered User
-
Mar 13th, 2002, 10:01 AM
#12
Good Ol' Platypus
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)
-
Mar 13th, 2002, 05:31 PM
#13
Why don't you just use the "Draw()" method of the ListImage item?, i.e.
VB Code:
ImageList1.ListImages(lFrame).Draw hDC, 0, 0, imlTransparent
-
Mar 13th, 2002, 05:52 PM
#14
Thread Starter
Registered User
Originally posted by Aaron Young
Why don't you just use the "Draw()" method of the ListImage item?, i.e.
VB Code:
ImageList1.ListImages(lFrame).Draw hDC, 0, 0, imlTransparent
I tried this Aaron:
VB Code:
Private Sub Timer1_Timer()
Static counter As Long
If counter = 9 Then
counter = 0
End If
If counter = 0 Then counter = 1
Debug.Print "now" & counter
ImageList1.ListImages(counter).Draw Picture1.hdc, 0, 0, imlTransparent
counter = counter + 1
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
-
Mar 13th, 2002, 05:57 PM
#15
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.
-
Mar 13th, 2002, 06:19 PM
#16
Thread Starter
Registered User
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.
-
Mar 13th, 2002, 06:28 PM
#17
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
-
Mar 13th, 2002, 06:31 PM
#18
This works for me:
VB Code:
Option Explicit
Private Sub Form_Load()
' Set the MaskColor to Black, because you're using Transparent GIF's
ImageList1.MaskColor = vbBlack
End Sub
Private Sub Timer1_Timer()
Static lFrame As Long
Picture1.AutoRedraw = True
Picture1.Cls ' Or Redraw BackGround
ImageList1.ListImages(lFrame + 1).Draw Picture1.hDC, 0, 0, imlTransparent
Picture1.AutoRedraw = False
lFrame = (lFrame + 1) Mod ImageList1.ListImages.Count
End Sub
-
Mar 13th, 2002, 06:52 PM
#19
Thread Starter
Registered User
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|