Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multi monitor XP, different color depths lead to greyscale variation

Posted on 2003-12-02
5
Medium Priority
?
280 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 520 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
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 …
Introduction to Processes

610 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