Solved

Drawing problems in 256 colours...

Posted on 1998-06-28
9
243 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  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 …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

746 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

14 Experts available now in Live!

Get 1:1 Help Now