home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 6
/
Eagles_Nest_Mac_Collection_Disc_6.TOAST
/
Windows
/
VisBasAPIex
/
VBAPIGUIDE.image
/
PALTEST.BAS
< prev
next >
Wrap
BASIC Source File
|
1992-10-16
|
6KB
|
195 lines
' Project PalTest
' Module containing global contstants and general purpose
' routines.
Option Explicit
Global Const PC_RESERVED = &H1
Global Const PC_EXPLICIT = &H2
Global Const PC_NOCOLLAPSE = &H4
Global Const DIB_RGB_COLORS = 0
Global Const DIB_PAL_COLORS = 1
Global Const SYSPAL_STATIC = 1
Global Const SYSPAL_NOSTATIC = 2
Global Const CF_TEXT = 1
Global Const CF_BITMAP = 2
Global Const CF_METAFILEPICT = 3
Global Const CF_SYLK = 4
Global Const CF_DIF = 5
Global Const CF_TIFF = 6
Global Const CF_OEMTEXT = 7
Global Const CF_DIB = 8
Global Const CF_PALETTE = 9
Global Const CF_OWNERDISPLAY = &H80
Global Const CF_DSPTEXT = &H81
Global Const CF_DSPBITMAP = &H82
Global Const CF_DSPMETAFILEPICT = &H83
Global Const CF_PRIVATEFIRST = &H200
Global Const CF_PRIVATELAST = &H2FF
' Increase this number to 32 or 64 to see the effect of
' the Zorder on the palettes.
Global Const PALENTRIES = 15
' This is similar to the LOGPALLETTE defined in
' APIDECS.BAS, however instead of using a buffer, we
' create a 64 entry palette for our use.
Type LOGPALETTE64
palVersion As Integer
palNumEntries As Integer
palPalEntry(PALENTRIES) As PALETTEENTRY
End Type
' And create a type safe alias to create palette that handles this structure
Declare Function CreatePalette64% Lib "GDI" Alias "CreatePalette" (lpLogPalette As LOGPALETTE64)
' The six palettes that this program will use are defined here
Global UsePalettes%(6)
Global logPalettes(6) As LOGPALETTE64
' This is a message used within Visual Basic to retrieve
' the handle of a palette
Global Const VBM_GETPALETTE% = &H101C
' This function creates 6 palettes that are used by
' the PalTest program
'
Sub CreateAllPalettes ()
Dim entrynum%
Dim oldmouseptr%
Dim x%
oldmouseptr% = Screen.MousePointer
Screen.MousePointer = 11
' Initialize the logical palette
For x% = 1 To 6
logPalettes(x%).palVersion = &H300
logPalettes(x%).palNumEntries = PALENTRIES
Next x%
' Palette 1 will be red
For entrynum% = 0 To PALENTRIES - 1
logPalettes(1).palPalEntry(entrynum%).peRed = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(1).palPalEntry(entrynum%).peGreen = Chr$(0)
logPalettes(1).palPalEntry(entrynum%).peBlue = Chr$(0)
logPalettes(1).palPalEntry(entrynum%).peFlags = Chr$(0)
Next entrynum%
' Palette 2 will be green
For entrynum% = 0 To PALENTRIES - 1
logPalettes(2).palPalEntry(entrynum%).peRed = Chr$(0)
logPalettes(2).palPalEntry(entrynum%).peGreen = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(2).palPalEntry(entrynum%).peBlue = Chr$(0)
logPalettes(2).palPalEntry(entrynum%).peFlags = Chr$(0)
Next entrynum%
' Palette 3 will be blue and can be animated
For entrynum% = 0 To PALENTRIES - 1
logPalettes(3).palPalEntry(entrynum%).peRed = Chr$(0)
logPalettes(3).palPalEntry(entrynum%).peGreen = Chr$(0)
logPalettes(3).palPalEntry(entrynum%).peBlue = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(3).palPalEntry(entrynum%).peFlags = Chr$(PC_RESERVED)
Next entrynum%
' Palette 4 will be yellow
For entrynum% = 0 To PALENTRIES - 1
logPalettes(4).palPalEntry(entrynum%).peRed = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(4).palPalEntry(entrynum%).peGreen = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(4).palPalEntry(entrynum%).peBlue = Chr$(0)
logPalettes(4).palPalEntry(entrynum%).peFlags = Chr$(0)
Next entrynum%
' Palette 5 will be Violet
For entrynum% = 0 To PALENTRIES - 1
logPalettes(5).palPalEntry(entrynum%).peRed = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(5).palPalEntry(entrynum%).peGreen = Chr$(0)
logPalettes(5).palPalEntry(entrynum%).peBlue = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(5).palPalEntry(entrynum%).peFlags = Chr$(0)
Next entrynum%
' Palette 6 will be grey
For entrynum% = 0 To PALENTRIES - 1
logPalettes(6).palPalEntry(entrynum%).peRed = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(6).palPalEntry(entrynum%).peGreen = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(6).palPalEntry(entrynum%).peBlue = Chr$((255 * entrynum%) / PALENTRIES)
logPalettes(6).palPalEntry(entrynum%).peFlags = Chr$(0)
Next entrynum%
' And create the palettes
For x% = 1 To 6
UsePalettes(x%) = CreatePalette64(logPalettes(x%))
Next x%
Screen.MousePointer = oldmouseptr%
End Sub
'
' We're doing color animation on the third picture box
' (that's blue)
'
Sub DoTheAnimate ()
Dim entrynum%
Dim usepal%
Dim holdentry As PALETTEENTRY
' Get a handle to the control's palette
usepal% = SendMessageByNum(PalTest.Picture1(2).hWnd, VBM_GETPALETTE, 0, 0)
' The following code simply loops the color values
LSet holdentry = logPalettes(3).palPalEntry(0)
For entrynum% = 0 To PALENTRIES - 2
LSet logPalettes(3).palPalEntry(entrynum%) = logPalettes(3).palPalEntry(entrynum% + 1)
Next entrynum%
LSet logPalettes(3).palPalEntry(PALENTRIES - 1) = holdentry
AnimatePalette usepal%, 0, PALENTRIES, logPalettes(3).palPalEntry(0)
End Sub
' FillPicture draws a spectrum in the specified picture
' control using the appropriate palette for that control
'
Sub FillPicture (picnum%)
Dim totwidth&, startloc&, endloc&
Dim pic As control
Dim x&
'Dim rc As RECT
'Dim usebrush%
'Dim t%
Set pic = PalTest.Picture1(picnum%)
totwidth& = pic.ScaleWidth
For x& = 0 To PALENTRIES - 1
' We're using long arithmetic for speed. Note the
' ordering of operations to preserve precesion
startloc& = (totwidth& * x&) / PALENTRIES
endloc& = (totwidth& * (x& + 1)) / PALENTRIES
pic.Line (startloc&, 0)-(endloc&, pic.ScaleHeight), GetPalColor(picnum%, (x&)), BF
Next x&
End Sub
'
' Gets the Long RGB color for a palette entry
'
Function GetPalColor& (picnum%, entry%)
Dim res&
Dim pe As PALETTEENTRY
LSet pe = logPalettes(picnum% + 1).palPalEntry(entry%)
' We build a long value using this rather awkward
' shifting technique.
' We actually could save time by performing a raw
' memory copy from the pe object into a long variable.
' since they are the same format.
res& = Asc(pe.peRed)
res& = res& Or (Asc(pe.peGreen) * 256&)
res& = res& Or (Asc(pe.peBlue) * 256& * 256&)
GetPalColor& = res&
End Function