Solved

Drawing problems in 256 colours...

Posted on 1998-06-28
9
253 Views
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??
0
Comment
Question by:greeneye
  • 5
  • 4
9 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1166752
When creating a pen, specify the color by using PALETTERGB instead of RGB.
0
 

Author Comment

by:greeneye
ID: 1166753
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?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1166754
Try using a brush. I remember that using a pen seemed not to work properly.
0
 

Author Comment

by:greeneye
ID: 1166755
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?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:chensu
ID: 1166756
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.
0
 

Author Comment

by:greeneye
ID: 1166757
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???
0
 
LVL 23

Expert Comment

by:chensu
ID: 1166758
Does it still work fine if using RGB instead of PALETTERGB?
0
 

Author Comment

by:greeneye
ID: 1166759
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
0
 
LVL 23

Expert Comment

by:chensu
ID: 1166760
I think the problem is due to both using RGB and not realizing the palette properly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now