Article View: comp.os.ms-windows.programmer.misc
Article #2412I don't understand LOGPALETTE struct
From: 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
Technical Details
Message-ID:
<1993Jan28.181610.19473@emr1.emr.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrantShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant From: jagrant@emr1.emr.ca (John Grant) Subject: I don't understand LOGPALETTE struct Message-ID: <1993Jan28.181610.19473@emr1.emr.ca> Organization: Energy, Mines, and Resources, Ottawa Date: Thu, 28 Jan 1993 18:16:10 GMT Lines: 75