Beispiel #1
0
 internal static extern IntPtr CreatePalette([In] ref LOGPALETTE lplgpl);
Beispiel #2
0
 public virtual void SetColorScheme(LOGPALETTE[] logicalPalette){
 }
        public static void SetPalette(IntPtr handle)
        {

            IntPtr htPalette = IntPtr.Zero; //Graphics.GetHalftonePalette();
            IntPtr hPalPrev = IntPtr.Zero;

            LOGPALETTE LogPal = new LOGPALETTE();

            int numentries = 256;
            int headsize = Marshal.SizeOf(typeof(LOGPALETTE0));
            int entrysize = Marshal.SizeOf(typeof(PALETTEENTRY));
            IntPtr buffer = Marshal.AllocHGlobal(headsize + (entrysize * numentries));

            LOGPALETTE0 logpal;
            logpal.palVersion = 0x300;
            logpal.palNumEntries = (short)numentries;
            Marshal.StructureToPtr(logpal, buffer, false);
            PALETTEENTRY pe = new PALETTEENTRY();

            int run = (int)buffer + headsize;
            for (int i = 0; i < numentries; i++)
            {
                pe.peBlue = 0;
                pe.peGreen = 0;
                pe.peRed = (byte)i;
                pe.peFlags = 0x4;

                Marshal.StructureToPtr(pe, (IntPtr)run, false);
                run += entrysize;
            }

            IntPtr hpal = CreatePalette(buffer);
            {
                IntPtr hwnd = GetDesktopWindow();
                IntPtr hdc = GetDC(hwnd);

                SetSystemPaletteUse(hdc, 2);

                //htPalette = CreatePalette(hpal);            //  Select the new palette into the memory DC and realize it.            
                hPalPrev = SelectPalette(hdc, hpal, false);
                int r = RealizePalette(hdc);
                hPalPrev = SelectPalette(hdc, hpal, false);
                r = RealizePalette(hdc);
                UpdateColors(hdc);
                ReleaseDC(hwnd, hdc);
            }

            //Marshal.FreeHGlobal(buffer);

        }