Solved

Multi monitor XP, different color depths lead to greyscale variation

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

777 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