?
Solved

Drawing problems in 256 colours...

Posted on 1998-06-28
9
Medium Priority
?
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 300 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

765 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