AnimatePalette 
Author Message
 AnimatePalette

Hello - Has anyone ever used the AnimatePalette function in GDI32 with any
success?  I trying too but with no success.  I am using a picture box with a
standard 16 color bmp.  AnimatePalette wants the handle to the bmp's palette
(hPal) which I have found using Picture1.Picture.hPal but it's value is
always 0.  What's up here?  I know the bitmap has to have a palette, why
isn't the hPal property returning it?
Thanks in advance for any help.


Mon, 08 Sep 2003 00:38:36 GMT  
 AnimatePalette
hPal is pretty useless: I've tried <g>.

Here's some code posted by Richard Mason which can be used to animate the
palette for a picture in an image control.

Jim Deutch
MS Dev MVP

Private Type RGBQUAD
    rgbBlue As Byte
    rgbGreen As Byte
    rgbRed As Byte
    rgbReserved As Byte
End Type

Private Declare Function CreateCompatibleDC& Lib "gdi32" (ByVal hDC As Long)
Private Declare Function DeleteDC& Lib "gdi32" (ByVal hDC As Long)
Private Declare Function GetDIBColorTable& Lib "gdi32" (ByVal hDC As Long,
ByVal un1 As Long, ByVal un2 As Long, pRGBQuad As Any)
Private Declare Function SetDIBColorTable& Lib "gdi32" (ByVal hDC As Long,
ByVal un1 As Long, ByVal un2 As Long, pcRGBQuad As Any)
Private Declare Function SelectObject& Lib "gdi32" (ByVal hDC As Long, ByVal
hObject As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command2_Click()

  Dim lret As Long
  Dim newhDC As Long
  Dim oldhand As Long
  Dim quadarray(255) As Long
  Dim icount As Long
  Dim i As Long
  Dim tmp As Long
  Static busy As Boolean

  busy = Not busy

  Do While True
      DoEvents
      If busy = False Then Exit Do

      newhDC = CreateCompatibleDC(0&)
      oldhand = SelectObject(newhDC, Image1.Picture)

      lret = GetDIBColorTable(newhDC, 0, 256, quadarray(0))

      'One can now modify the color table as required
      tmp = quadarray(0)
      For i = 1 To 255
        quadarray(i - 1) = quadarray(i)
      Next i
      quadarray(255) = tmp

      'Write back the modified color table
      lret = SetDIBColorTable(newhDC, 0, 256, quadarray(0))

      'Cleanup
      SelectObject newhDC, oldhand
      DeleteDC newhDC

      Image1.Refresh
      Sleep 1
    Loop

End Sub


Quote:
> Hello - Has anyone ever used the AnimatePalette function in GDI32 with any
> success?  I trying too but with no success.  I am using a picture box with
a
> standard 16 color bmp.  AnimatePalette wants the handle to the bmp's
palette
> (hPal) which I have found using Picture1.Picture.hPal but it's value is
> always 0.  What's up here?  I know the bitmap has to have a palette, why
> isn't the hPal property returning it?
> Thanks in advance for any help.



Mon, 08 Sep 2003 01:14:48 GMT  
 AnimatePalette
Thanks for your help, the code works great!


Quote:
> hPal is pretty useless: I've tried <g>.

> Here's some code posted by Richard Mason which can be used to animate the
> palette for a picture in an image control.

> Jim Deutch
> MS Dev MVP

> Private Type RGBQUAD
>     rgbBlue As Byte
>     rgbGreen As Byte
>     rgbRed As Byte
>     rgbReserved As Byte
> End Type

> Private Declare Function CreateCompatibleDC& Lib "gdi32" (ByVal hDC As
Long)
> Private Declare Function DeleteDC& Lib "gdi32" (ByVal hDC As Long)
> Private Declare Function GetDIBColorTable& Lib "gdi32" (ByVal hDC As Long,
> ByVal un1 As Long, ByVal un2 As Long, pRGBQuad As Any)
> Private Declare Function SetDIBColorTable& Lib "gdi32" (ByVal hDC As Long,
> ByVal un1 As Long, ByVal un2 As Long, pcRGBQuad As Any)
> Private Declare Function SelectObject& Lib "gdi32" (ByVal hDC As Long,
ByVal
> hObject As Long)
> Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

> Private Sub Command2_Click()

>   Dim lret As Long
>   Dim newhDC As Long
>   Dim oldhand As Long
>   Dim quadarray(255) As Long
>   Dim icount As Long
>   Dim i As Long
>   Dim tmp As Long
>   Static busy As Boolean

>   busy = Not busy

>   Do While True
>       DoEvents
>       If busy = False Then Exit Do

>       newhDC = CreateCompatibleDC(0&)
>       oldhand = SelectObject(newhDC, Image1.Picture)

>       lret = GetDIBColorTable(newhDC, 0, 256, quadarray(0))

>       'One can now modify the color table as required
>       tmp = quadarray(0)
>       For i = 1 To 255
>         quadarray(i - 1) = quadarray(i)
>       Next i
>       quadarray(255) = tmp

>       'Write back the modified color table
>       lret = SetDIBColorTable(newhDC, 0, 256, quadarray(0))

>       'Cleanup
>       SelectObject newhDC, oldhand
>       DeleteDC newhDC

>       Image1.Refresh
>       Sleep 1
>     Loop

> End Sub



> > Hello - Has anyone ever used the AnimatePalette function in GDI32 with
any
> > success?  I trying too but with no success.  I am using a picture box
with
> a
> > standard 16 color bmp.  AnimatePalette wants the handle to the bmp's
> palette
> > (hPal) which I have found using Picture1.Picture.hPal but it's value is
> > always 0.  What's up here?  I know the bitmap has to have a palette, why
> > isn't the hPal property returning it?
> > Thanks in advance for any help.



Mon, 08 Sep 2003 02:52:43 GMT  
 AnimatePalette
I couldn't get the code to work.  I'm using a 256 color .bmp in an image
control.  I even tried changing my display settings to 256 color mode.  Any
ideas what I might be doing wrong?
Thanks,
Chris


Quote:
> hPal is pretty useless: I've tried <g>.

> Here's some code posted by Richard Mason which can be used to animate the
> palette for a picture in an image control.



Wed, 10 Sep 2003 22:38:55 GMT  
 AnimatePalette
Chris,

I just copied the code exactly as is into a new project, loaded a 256 color
bmp into Image1, added a button (Command2) and ran the program.
It worked without a hitch. Make sure you haven't changed any code or missed
some code when copying to your project. Other than that, I don't know why
yours isn't working.

I tested on Win98, WinNT and Win2K. No problems.

Make sure both of the following lines are returning 256:
      lret = GetDIBColorTable(newhDC, 0, 256, quadarray(0))
      lret = SetDIBColorTable(newhDC, 0, 256, quadarray(0))

You can just put a break after each line and check the value of lret.
Also make sure that newhDC and oldhand values are not zero.

Rocky Clark (Kath-Rock Software)


Quote:
> I couldn't get the code to work.  I'm using a 256 color .bmp in an image
> control.  I even tried changing my display settings to 256 color mode.
Any
> ideas what I might be doing wrong?
> Thanks,
> Chris



> > hPal is pretty useless: I've tried <g>.

> > Here's some code posted by Richard Mason which can be used to animate
the
> > palette for a picture in an image control.



Thu, 11 Sep 2003 01:07:59 GMT  
 AnimatePalette
Just figured out what I did wrong...the SelectObject declare had "ByVal" and
"hObject" run together as one word!!  Bad paste job I guess :)
Thanks,
Chris


Thu, 11 Sep 2003 03:32:09 GMT  
 AnimatePalette
BTW, It looks purty cool with a spectrum gradient as the image. :)
Chris


Thu, 11 Sep 2003 03:33:55 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Using AnimatePalette, SetPalette.....etc...

2. AnimatePalette in VB Pro 3.0

3. AnimatePalette help in VBPro 3.0

4. VB3 ANIMATEPALETTE how?

5. AnimatePalette API

6. AnimatePalette

7. Visual Basic 5.0 and API AnimatePalette

8. AnimatePalette

9. VB5 and AnimatePalette

10. AnimatePalette trouble run-time

11. AnimatePalette could be fun ..... if I was smarter!!

 

 
Powered by phpBB® Forum Software