Solved

Multi monitor XP, different color depths lead to greyscale variation

Posted on 2003-12-02
5
275 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

856 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