greeneye
asked on
Drawing problems in 256 colours...
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??
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??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try using a brush. I remember that using a pen seemed not to work properly.
ASKER
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?
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.
ASKER
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???
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?
ASKER
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.
Cheers,
Don
Thanks for that. If you reply to this I will grade you on that at least.
Cheers,
Don
I think the problem is due to both using RGB and not realizing the palette properly.
ASKER
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?