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.  
hoffmsjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
There are two types of palletes.  There are logical palletes and system palletes.  An application uses a logical pallete to specify the colors iit would like to use.  However the logical pallete may specify different colors than will actually be used on the screen or other device that the GUI is drawing to.  This is because logical palletes can specify an unlimited number of any of the 32bit RGB colors, but the devices themselves might not be able to specify as many colors simultaneously or even any 32bit color.  So the device has a system (device) pallete, that specifies the colors that the device can currently display.

continues
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
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.
0
hoffmsjAuthor Commented:
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?
0
nietodCommented:
>> 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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.