Link to home
Start Free TrialLog in
Avatar of hoffmsj
hoffmsj

asked on

Gui Pallete control

I'm trying to make a simple gui in C++ and so far I have just about everything working great except pallete control.  How can different GUI objects request and use the limited number of colors available on the screen at any one time? What is the best way to keep track of this? How does Windows do this;  you can often see pallete "mistakes" when switching between color intensive apps.  
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

The way usually is used  that you create logical palletes that contains all the colors that your application needs.  You then use RealizePalette() to try to map the colors of your logical palette into the dervice.  It will map the colors as best as possible, if any colors can't be mapped, it will try to draw then using the closest color that is in the palette.

How if the device we are talking about is the screen (rather than say a printer) you will have to share the pallete with all the other applications (and the OS) currrently running.  To allow this to work better the OS gives the foreground application an opportunity to map its pallete into the display, in this way the foreground app will appear in the best colors possible and the background apps will appear in the closest colors that can be found.  Then when a background map is moved to the foreground its colors will be mapped in to make it look better  To provide this mechanism, the OS sends a WM_QUERYNEWPALETTE to the top-level window of an application when the application window is activated.  The window should use this as an opportunity to realize its palette.

Let me know if you have any questions.
Avatar of hoffmsj

ASKER

Thanks! Very helpful but a little confusing.  What would the RealizePalette() function do?  What would be a good way to write a funtion to find the closest color to a color already in the displaying pallete?
>> What would the RealizePalette() function do?
Read the docs on it.   It converts the associated device so it can display as many of the colors from the logical palette as it can.

>> What would be a good way to write a
>> funtion to find the closest color to a color
>> already in the displaying pallete?
Its already written.  Look at GetNearestColor() and GetNearestPaletteIndex()

This stuff is all well documented in the VC help.