Thread View: comp.os.ms-windows.programmer.misc
1 messages
1 total messages
Started by John Grant
Thu, 28 Jan 1993 18:16
I don't understand LOGPALETTE struct
Author: John Grant
Date: Thu, 28 Jan 1993 18:16
Date: Thu, 28 Jan 1993 18:16
75 lines
3207 bytes
3207 bytes
Attached at the bottom is the example from the on-line help for
CreatePalette(). Could someone help me understand this?
1. here is the LOGPALETTE struct from windows.h:
typedef struct tagLOGPALETTE{
WORD palVersion;
WORD palNumEntries;
PALETTEENTRY palPalEntry[1]; } LOGPALETTE;
I have 2 possible interpretations of this:
1. palPalEntry *is* the entire array of PALETTEENTRY and
is part of the struct and must be contiguous with the
rest of the struct. If so, this is a variable size
struct, depending on the no. of colours. Therefore
sizeof(LOGPALETTE) is meaningless, right? (I have no
occasion to use this - just wondering).
2. palPalEntry is a pointer to an array of LOGPALETTE and
can be located anywhere. If this is the case, why
didn't they make it:
PALETTEENTRY *palPalEntry;
So the simple questions are:
1. Why is palPalEntry sized as [1]? Is this their way (or
a standard C way I don't know about) of saying the array is
a user-defined size, *but* must be located contiguous
with the rest of the struct?
2. does the array have to be contiguous (i.e. within the struct)
2. what is 'ape' used for here - it is filled, but never used.
3. why is 'ape' needed at all? - if the array of PALETTEENTRY things
is already declared inside the allocated LOGPALETTE *lgpl?
4. Supplementary question:
Should I use AnimatePalette() or RealizePalette() and what
is the difference? Do I use RealizePalette() only for the
first time and AnimatePalette() for subsequent colour
changes?
John A. Grant jagrant@emr1.emr.ca
Airborne Geophysics
Geological Survey of Canada, Ottawa
----------------Example from on-line help for CreatePalette-------------
Example
The following example initializes a LOGPALETTE structure and an array
of PALETTEENTRY structures, and then uses the CreatePalette function to
retrieve a handle of a logical palette:
#define NUMENTRIES 128
HPALETTE hpal;
PALETTEENTRY ape[NUMENTRIES];
plgpl = (LOGPALETTE*) LocalAlloc(LPTR,
sizeof(LOGPALETTE) + cColors * sizeof(PALETTEENTRY));
plgpl->palNumEntries = cColors;
plgpl->palVersion = 0x300;
for(i=0,red=0,green=127,blue=127;i<NUMENTRIES;i++,red+=1,green+=1,blue+=1){
ape[i].peRed =plgpl->palPalEntry[i].peRed =LOBYTE(red);
ape[i].peGreen=plgpl->palPalEntry[i].peGreen=LOBYTE(green);
ape[i].peBlue =plgpl->palPalEntry[i].peBlue =LOBYTE(blue);
ape[i].peFlags=plgpl->palPalEntry[i].peFlags=PC_RESERVED;
}
hpal=CreatePalette(plgpl);
LocalFree((HLOCAL) plgpl);
.
. /* Use the palette handle. */
.
DeleteObject(hpal);
---------------------------------------------------------------------
--
John A. Grant jagrant@emr1.emr.ca
Airborne Geophysics
Geological Survey of Canada, Ottawa
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads