[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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.  
  • 3
1 Solution
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.

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.
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?
>> 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.

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now