Solved

Drawing problems in 256 colours...

Posted on 1998-06-28
9
263 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why "." vs "->" 23 120
Converting to C# also VS2015 5 125
Least Squares Curve Fitting 4 77
How to properly read C++ console input into several variables with scanf 2 11
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 how to clear a vector as well as how to detect empty vectors in C++.

770 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