Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

  1. /*-----------------------------------------------------------------------
  2. | stdpal.c
  3. |
  4. | Standard App Palette useful for OLE applications. v 1.01
  5. |
  6. | NOTE: Palette MUST be created with OleStdCreateStandardPalette
  7. |
  8. | Copyright (c) 1992 - 1993 Microsoft Corporation. All rights reserved.
  9. |
  10. -----------------------------------------------------------------------*/
  11. #ifndef PC_RESERVED
  12. #ifndef INC_OLE2
  13. #define INC_OLE2
  14. #endif
  15. #undef UNICODE
  16. #include <windows.h>
  17. #include <ole2.h>
  18. #endif
  19. #include "stdpal.h"
  20. #define cpeAppPal 256 // number of colors in our apps palette
  21. typedef struct
  22. {
  23. WORD wVersion;
  24. WORD cpe;
  25. PALETTEENTRY rgpe[cpeAppPal];
  26. } LOGPAL;
  27. /*-----------------------------------------------------------------------
  28. | OleStdCreateStandardPalette
  29. |
  30. | Creates the standard Apps palette. Create one of these for your
  31. | app, and select/realize it into each DC.
  32. |
  33. | Arguments:
  34. | void:
  35. |
  36. | Returns:
  37. |
  38. | Keywords:
  39. -----------------------------------------------------------------------*/
  40. STDAPI_(HPALETTE) OleStdCreateStandardPalette(void)
  41. {
  42. HDC hdc;
  43. HPALETTE hpal;
  44. hpal = (HPALETTE) NULL;
  45. hdc = GetDC(NULL);
  46. if (hdc != NULL && GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)
  47. {
  48. int cpeSysPal;
  49. int cpeReserved;
  50. cpeSysPal = GetDeviceCaps(hdc, SIZEPALETTE);
  51. cpeReserved = GetDeviceCaps(hdc, NUMRESERVED);
  52. if (cpeSysPal > cpeReserved)
  53. {
  54. int cpeReserved2;
  55. unsigned char FAR* lpb;
  56. PALETTEENTRY FAR* ppe;
  57. PALETTEENTRY FAR* ppeMac;
  58. LOGPAL logpal;
  59. cpeReserved2 = cpeReserved/2;
  60. // Get the system palette entries at the beginning and end.
  61. GetSystemPaletteEntries(hdc, 0, cpeReserved2, logpal.rgpe);
  62. GetSystemPaletteEntries(hdc, cpeSysPal - cpeReserved2, cpeReserved2,
  63. &logpal.rgpe[cpeAppPal-cpeReserved2]);
  64. logpal.cpe = cpeAppPal;
  65. logpal.wVersion = 0x300;
  66. lpb = (BYTE FAR *) &palSVGA[10];
  67. ppe = (PALETTEENTRY FAR*)&logpal.rgpe[cpeReserved2];
  68. ppeMac = (PALETTEENTRY FAR*)&logpal.rgpe[cpeAppPal-cpeReserved2];
  69. while (ppe < ppeMac)
  70. {
  71. ppe->peFlags = PC_NOCOLLAPSE;
  72. ppe->peRed = *lpb++;
  73. ppe->peGreen = *lpb++;
  74. ppe->peBlue = *lpb++;
  75. ppe++;
  76. }
  77. hpal = CreatePalette((LOGPALETTE FAR *)&logpal);
  78. }
  79. }
  80. ReleaseDC(NULL, hdc);
  81. return hpal;
  82. }