We help IT Professionals succeed at work.

Drawing problems in 256 colours...

greeneye asked
Last Modified: 2010-04-01
I am writing an Active-X control which is basically a charting package.  All lines have user-defineable colours and under 65536 colours all colours appear correctly.  However, under 256 colours all non-solid colours are approximated by windows.
I have gone about creating a logical palette, have copied all default colours into it (enumerating solid pens), have selected the palette into the DC and have realised the palette.  This happens initially.
When a new pen colour is added, the palette is resized, the new colour added and the palette realised.  This is all as per the Win32 SDK docs.
The problem is that the new colours are *still* approximated to one of the solid colours in the default palette, even though I have selected a logical palette into the DC.
Any ideas??  Could this be a problem with Active-X controls??
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)


Okay, have passed the COLORREF using the PALETTERGB macro.  Still no better.  Have checked the pen after creation and it retains the correct colour.  Have followed its progress through the code until it is selected and draws (simple MoveTo and LineTo CDC calls).  Pen colour is still as expected.

Have also tried using the PALETTEINDEX macro with the colour's index in the palette.  The colour always appears as black which tends to suggest that the logical palette is not realised properly.  Any further thoughts or pointers to sample code?

Try using a brush. I remember that using a pen seemed not to work properly.


But line drawing functions use the current pen.  My application is a charting control and so line drawing is necessary.  I really need to sort out the CPen implementation.

Is there anything that I am not doing in setting up the logical palette?

Now you need to find out where the problem comes from. So, try using a brush first to see if it works. If not, your palette is not set properly or not realized properly.


Have found the problem Chensu.
I made the horrible mistake in thinking that once you have realised the palette into the DC passed by OnDraw() then the logical palette would always be set.  I am now selecting and realising the palette on each occurence of OnDraw (and not just the first time).  Works fine now - stupid mistake.

Thanks for your help anyway.
Erm... how do I grade this???

Does it still work fine if using RGB instead of PALETTERGB?


Nah, I have to change all the code to update this - will take days...
Thanks for that.  If you reply to this I will grade you on that at least.


I think the problem is due to both using RGB and not realizing the palette properly.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.