oracle@dayton.saic.com (10/04/90)
I have a question about modifying the system palette using the Microsoft Windows SDK (Ver 3.0 )! How is it done!? I need to reset the palette to 16 solid shades of gray for an imagery display application. The following summarizes the steps I used unsuccessfully! NPLOGPALETTE pLogPal; . . . hDC = GetDC( hWnd ); pLogPal = (NPLOGPALETTE) LocalAlloc (LMEM_FIXED, (sizeof (LOGPALETTE) + (sizeof (PALETTEENTRY) * (PALETTESIZE)))); pLogPal->palVersion = 0x300; pLogPal->palNumEntries = PALETTESIZE; /* 16 */ pLogPal->palPalEntry[0].peRed = (BYTE)0; pLogPal->palPalEntry[0].peGreen = (BYTE)0; pLogPal->palPalEntry[0].peBlue = (BYTE)0; pLogPal->palPalEntry[0].pePlags = (BYTE)0; . . /* Entries 1 thru 15 set */ . /* 17, 34, 51, 68, 85, 102, 119, */ . /* 136, 153, 170, 204, 221, 238, 255 */ . hPal = CreatePalette( (LPLOGPALETTE) pLogPal); SetSystemPaletteUse( hDC, SYSPAL_NOSTATIC ); SelectPalette( hDC, hPal, 1); RealizePalette( hDC ); SendMessage( 0xFFFF, WM_SYSCOLORCHANGE, NULL, NULL ); . . . When I attempt to post pixels to the screen, I use the following call. SetPixel( hDC, x, y, RGB( 17, 17, 17 ) ); /* Explicit RGB Call */ The explicit grey scales I define in my logical palette are not mapped into the non-static system palette! I am really frustrated, and would appreciate any help! Please mail responses to the address posted below. THANX in ADVANCE! Tim G. _____________________________________________________________________________ ____ ____ ___ Tim Granger /___ /___/ / / Science Applications International Corporation ____// / / /___ Dayton, Ohio ----------------------------------------------------------------------------- Internet: Oracle@Dayton.SAIC.COM uucp: uunet!dayvb!Oracle
roberth@microsoft.UUCP (Robert HESS) (10/09/90)
Tim Granger (oracle@dayton.saic.com) Asks: ---------------------------------------------------------------------------- I have a question about modifying the system palette using the Microsoft Windows SDK (Ver 3.0 )! How is it done!? I need to reset the [system] palette to 16 solid shades of gray for an imagery display application. The following summarizes the steps I used unsuccessfully! [...code was removed...] You didn't mention what display driver you are using. On an EGA, it is of course a 'no-go', and VGA will only work if the VGA driver you are using is palette aware. The current VGA driver was not Palette aware, because the _only_ time it would be able to do anything would be if you wanted to hack on the system colors. Any application that is wanting to do *anything* with the Palette Manager should first be checking to see if the current device supports palettes. An application can still do non-display things with the Palettes, but the user should be informed that their current display does not support the Palette Manager, so that they realize why things may not quite work like they were expecting. This code looks like: hdc = GetWindowDC (hwnd); iCaps = GetDeviceCaps (hdc, RASTERCAPS); if (iCaps & RC_PALETTE) { MessageBox (GetFocus(), "Device Supports Palettes", szAppTitle, MB_OK); } else { MessageBox (GetFocus(), "Device Does Not Support Palettes", szAppTitle, MB_OK); } ReleaseDC (hwnd, hdc); The next thing it should do, is check to see what the color resolution (bits per pixel) is for the device. This is not critical, but it will help the application to better manage its color selection methods. This code looks like: hdc = GetWindowDC (hwnd); fPalette = (GetDeviceCaps (hdc, RASTERCAPS)&RC_PALETTE); if (fPalette) { iCaps = GetDeviceCaps (hdc, COLORRES); wsprintf (szMsg, "COLORRES = %d", iCaps); MessageBox (GetFocus(), szMsg, szAppTitle, MB_OK); } else { MessageBox (GetFocus(), "Device Does Not Support Palettes", szAppTitle, MB_OK); } ReleaseDC (hwnd, hdc); And if you are manipulating the palette colors, either the System Palette, or the Standard Palette, then during development, you probably want to be running the example application 'MyPal' so that you can easily verify if your palette manipulations are being performed. MyPal sets all of its entries to PC_EXPLICIT so that you can look straight down to the current hardware palette. -Robert __________________________________________________________________________ ##### ####### | Robert B. Hess | ###### ####### | Technical ISV Manager - Developer Relations Group | ####### ####### | roberth@microsof.uu.net | #### ##### #### | Microsoft Corp., Redmond Wa (206)882-8080 | #### ### #### |_____________________________________________________| "...my opinions are strictly my own, and not those of my employer..."