home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / mswindo / programm / misc / 5458 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.0 KB  |  85 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!cs.utexas.edu!torn!nott!emr1!jagrant
  3. From: jagrant@emr1.emr.ca (John Grant)
  4. Subject: I don't understand LOGPALETTE struct
  5. Message-ID: <1993Jan28.181610.19473@emr1.emr.ca>
  6. Organization: Energy, Mines, and Resources, Ottawa
  7. Date: Thu, 28 Jan 1993 18:16:10 GMT
  8. Lines: 75
  9.  
  10. Attached at the bottom is the example from the on-line help for
  11. CreatePalette().  Could someone help me understand this?
  12.  
  13. 1. here is the LOGPALETTE struct from windows.h:
  14.     typedef struct tagLOGPALETTE{
  15.     WORD    palVersion;
  16.     WORD    palNumEntries;
  17.     PALETTEENTRY palPalEntry[1];    } LOGPALETTE;
  18.    I have 2 possible interpretations of this:
  19.     1. palPalEntry *is* the entire array of PALETTEENTRY and
  20.        is part of the struct and must be contiguous with the
  21.        rest of the struct.  If so, this is a variable size
  22.        struct, depending on the no. of colours.  Therefore
  23.        sizeof(LOGPALETTE) is meaningless, right? (I have no
  24.        occasion to use this - just wondering).
  25.     2. palPalEntry is a pointer to an array of LOGPALETTE and
  26.        can be located anywhere.  If this is the case, why
  27.        didn't they make it:
  28.         PALETTEENTRY *palPalEntry;
  29.  
  30.    So the simple questions are:
  31.      1. Why is palPalEntry sized as [1]?  Is this their way (or
  32.     a standard C way I don't know about) of saying the array is
  33.     a user-defined size, *but* must be located contiguous
  34.     with the rest of the struct?
  35.      2. does the array have to be contiguous (i.e. within the struct)
  36.     
  37. 2. what is 'ape' used for here - it is filled, but never used.
  38.  
  39. 3. why is 'ape' needed at all? - if the array of PALETTEENTRY things
  40.    is already declared inside the allocated LOGPALETTE *lgpl?
  41.  
  42. 4. Supplementary question:
  43.    Should I use AnimatePalette() or RealizePalette() and what
  44.    is the difference?  Do I use RealizePalette() only for the
  45.    first time and AnimatePalette() for subsequent colour
  46.    changes?
  47.  
  48. John A. Grant                        jagrant@emr1.emr.ca
  49. Airborne Geophysics
  50. Geological Survey of Canada, Ottawa
  51.  
  52. ----------------Example from on-line help for CreatePalette-------------
  53. Example
  54. The following example initializes a LOGPALETTE structure and an array 
  55. of PALETTEENTRY structures, and then uses the CreatePalette function to 
  56. retrieve a handle of a logical palette: 
  57.  
  58. #define NUMENTRIES 128
  59. HPALETTE hpal;
  60. PALETTEENTRY ape[NUMENTRIES];
  61.  
  62. plgpl = (LOGPALETTE*) LocalAlloc(LPTR,
  63.     sizeof(LOGPALETTE) + cColors * sizeof(PALETTEENTRY));
  64.  
  65. plgpl->palNumEntries = cColors;
  66. plgpl->palVersion = 0x300;
  67.  
  68. for(i=0,red=0,green=127,blue=127;i<NUMENTRIES;i++,red+=1,green+=1,blue+=1){
  69.     ape[i].peRed  =plgpl->palPalEntry[i].peRed  =LOBYTE(red);
  70.     ape[i].peGreen=plgpl->palPalEntry[i].peGreen=LOBYTE(green);
  71.     ape[i].peBlue =plgpl->palPalEntry[i].peBlue =LOBYTE(blue);
  72.     ape[i].peFlags=plgpl->palPalEntry[i].peFlags=PC_RESERVED;
  73. }
  74. hpal=CreatePalette(plgpl);
  75. LocalFree((HLOCAL) plgpl);
  76. .
  77. . /* Use the palette handle. */
  78. .
  79. DeleteObject(hpal);
  80. ---------------------------------------------------------------------
  81. -- 
  82. John A. Grant                        jagrant@emr1.emr.ca
  83. Airborne Geophysics
  84. Geological Survey of Canada, Ottawa
  85.