Solved

Multi monitor XP, different color depths lead to greyscale variation

Posted on 2003-12-02
5
277 Views
Last Modified: 2010-04-17
We have written a display driver for an 8 bit greyscale device.
In a multimon system for XP, our display is used along with a display adapter that has 24 bit color. When an icon is dragged over the greyscale monitor, the background color(greyscale) changes. This new color is always a number of the form (n%8) = 4, nearest to the original color/greyscale.

How can we handle the translation of olors from 24 bit depth to 8 bit in the display driver?
0
Comment
Question by:rajatk
[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
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 130 total points
ID: 9859429
Ugh, ugly problem I faced a while back.  The short answer is you can't directly.

It sounds like the same problem I had when I tried to draw in the screen DC.  The problem is that the screen DC is always the color depth of the primary monitor, and all other monitors are drawn using a very inneficient (I'd call it buggy) built in system method before being re-drawn to the proper graphics driver.

The solution I came up with was to decouple the drawing routine from the draw message. When it is a different function that takes a DC as a parameter it makes this easy (so the separation is the hard part).  Then you write another function like this:

BOOL CALLBACK MyDrawingEnumProc (HMONITOR hMonitor, HDC hDC,
                              LPRECT lpRect, LPARAM dwData)
{
   ENUM_CONTEXT     *pContext = (ENUM_CONTEXT *)dwData;
   HWND             hWnd = pContext->hWnd;

   // Make sure a zero width clip rect is never used.
   if ((lpRect->left == 0) && (lpRect->right == 0))
      return TRUE;

   // Call the original paint proc, alter the parameters which were passed in the struct
   // to match whatever parameters your paint function needed.
   MyPaintProc(hWnd, hDC, lpRect, FALSE, pContext->param1, pContext->param2, ...);

   // Before we return, see if the window was invalidated
   // in the middle of the paint, and if so remind Windows
   // to redraw the area that it caused us to miss.
   RECT rcClip;
   GetClipBox (hDC, &rcClip);
   if ((rcClip.left == 0) && (rcClip.right == 0))
   {
      InvalidateRect (hWnd, lpRect, FALSE);
   }

   return (TRUE);
}
 
Now you can call the montior enumerations from your normal paint handler like this:

   // You probably want to compute this bool only once and make it static (or global)
   bool bHasMultimonitorSupport;
   OSVERSIONINFO version;
   version.dwOSVersionInfoSize = sizeof(version);
   GetVersionEx (&version);
   if ((version.dwMajorVersion < 4) ||
       ((version.dwMajorVersion == 4) && (version.dwMinorVersion == 0)))
       bHasMultimonitorSupport = false;
   else
      bHasMultimonitorSupport = true;
   if (bHasMultimonitorSupport)
      EnumDisplayMonitors (hDC, rcPaint, MyDrawingEnumProc, (long)&EnumContext);
   else
       MyDrawingEnumProc((HMONITOR)1, hDC, rcPaint, (LPARAM)&EnumContext);

By calling the drawing routine only for the DC specific to the monitor you are drawing to, Windows doesn't do the "double translation" that causes the drawing inaccuracies.

Hope this helps.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 10322675
I assume rajatk will correct me if I'm wrong, but the lack of a response suggests either this was a solution or a decision was made that the process was too difficult to be worth it.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

729 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