How to Determine the Number of Supported ColorsLast reviewed: December 3, 1995Article ID: Q140488 |
The information in this article applies to:
SUMMARYSometimes it is necessary to determine how many colors the current video driver supports. For example, a distributed application may require 256 color support so that it will run correctly. This article explains how to retrieve that information using the GetDC(), GetDeviceCaps(), and ReleaseDC() Windows API functions.
MORE INFORMATIONGetDeviceCaps() is used to determine the number of colors the current video driver will support. The formula for the number of colors is:
2^(PLANES * BITSPIXEL)PLANES is number of color planes that the driver supports, and BITSPIXEL is the number of adjacent color bits for each pixel. For a more detailed description of PLANES and BITSPIXEL, please refer to the Visual C++ manual or Help file and the MSDN compact disc.
Visual FoxPro 3.0 Code SampleThe following code can be used in Visual FoxPro for Windows only. See second code sample for code that works in FoxPro 2.5x and 2.6x. * -- 3.0 Code begins here
DECLARE INTEGER GetDC IN WIN32API INTEGER piGetDC iDCHandle = GetDC(0) *-- The following are the constants used by GetDeviceCaps *-- Additional values can be found in C++ and the MSDN compact disc. PLANES = 14 BITSPIXEL = 12 DECLARE INTEGER GetDeviceCaps IN WIN32API INTEGER piDCHandle, ; INTEGER piNumColors iPlanes=GetDeviceCaps(iDCHandle, PLANES) iBitsPixel=GetDeviceCaps(iDCHandle,BITSPIXEL) *-- Returns the number of colors used by the driver iNumColors = 2^(iPlanes * iBitsPixel) WAIT WINDOW "Number of colors this driver supports is " ; +ALLTRIM(STR(iNumColors)) *-- The following code releases the GetDC handle DECLARE INTEGER ReleaseDC IN Win32API INTEGER piHandle, ; INTEGER piDCHandle =ReleaseDC(0,iDCHandle) *-- 3.0 Code ends here FoxPro 2.5x and 2.6x Code SampleThe following code is written for 2.5x and 2.6x versions of FoxPro.
*-- Code begins here SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL" ADDITIVE *-- Gets a Device Context to the video driver. Zero is *-- used to get the DC for the screen iGetDC = RegFN("GetDC","I","I") iDCHandle = CallFN(iGetDC,0) *-- The following are the constants used by GetDeviceCaps *-- Additional values can be found in C++ and the MSDN compact disc. PLANES = 14 BITSPIXEL = 12 iGetDevCaps = RegFN("GetDeviceCaps","II","I") iPlanes=CallFN(iGetDevCaps,iDCHandle, PLANES) iBitsPixel=CallFN(iGetDevCaps,iDCHandle,BITSPIXEL) *-- Returns the number of colors used by the driver iNumColors = 2^(iPlanes * iBitsPixel) WAIT WINDOW "Number of colors this driver supports is "; +ALLTRIM(STR(iNumColors)) *-- The following code releases the GetDC handle iReleaseDC = RegFN("ReleaseDC","II","I") =CallFN(iReleaseDC,0,iDCHandle) RELEASE LIBRARY SYS(2004)+"FOXTOOLS.FLL" *-- Code ends hereThis code was designed to work under all Windows platforms supported by Microsoft FoxPro.
|
Additional reference words: 3.00 VFoxWin
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |