Click to Rate and Give Feedback
MSDN
MSDN Library
Reference
Functions
 SetDeviceGammaRamp
Windows Color System
SetDeviceGammaRamp

The SetDeviceGammaRamp function sets the gamma ramp on direct color display boards having drivers that support downloadable gamma ramps in hardware.

BOOL WINAPI SetDeviceGammaRamp(
  HDC hDC,
  LPVOID lpRamp
);

Parameters

hDC
Specifies the device context of the direct color display board in question.
lpRamp
Pointer to a buffer containing the gamma ramp to be set. The gamma ramp is specified in three arrays of 256 WORD elements each, which contain the mapping between RGB values in the frame buffer and digital-analog-converter (DAC) values. The sequence of the arrays is red, green, blue. The RGB values must be stored in the most significant bits of each WORD to increase DAC independence.

Return Values

If this function succeeds, the return value is TRUE.

If this function fails, the return value is FALSE.

Remarks

Direct color display modes do not use color lookup tables and are usually 16, 24, or 32 bit. Not all direct color video boards support loadable gamma ramps. SetDeviceGammaRamp succeeds only for devices with drivers that support downloadable gamma ramps in hardware.

Requirements

  Windows NT/2000/XP/Vista: Included in Windows 2000 and later.
  Windows 95/98/Me: Included in Windows 95 and later.
  Header: Declared in Wingdi.h.
  Library: Use Gdi32.lib.

See Also

Basic Color Management Concepts, Functions

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Returns FALSE, GetLastError() returns ERROR_INVALID_PARAMETER      jkriegshauser   |   Edit   |  
It's a subtle point, but make sure hDC is a device context for one of your display devices, not the entire desktop. This might be the reason if you happen to have SetDeviceGammaRamp() returning FALSE and GetLastError() reporting ERROR_INVALID_PARAMETER. You can find display devices using EnumDisplayMonitors() and GetMonitorInfo().

Another interesting side effect is that sometimes it appears that the provided gamma ramp provided may be modified by SetDeviceGammaRamp(). This also appears to be device dependent. It's best to make a copy of the gamma ramp if you are setting it from a ramp that you're holding on to for a reference ramp or other needs.

Sample code:
D3DGAMMARAMP* g_pRamp = 0;

BOOL CALLBACK EnumMonitorProc( HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData )
{
MONITORINFOEX info;
info.cbSize = sizeof(info);
if ( GetMonitorInfo( hMonitor, (LPMONITORINFO)info ) == TRUE )
{
HDC hDC = CreateDC( _T("DISPLAY"), info.szDevice, 0, 0 );
if ( hDC != 0 )
{
D3DGAMMARAMP localRamp = *g_pRamp;
SetDeviceGammaRamp( hDC, &localRamp );
DeleteDC( hDC );
}
}

// Continue to next device
return TRUE;
}
void SetGammaRampAllDisplays( D3DGAMMARAMP* pRamp )
{
// Set the global ramp for the callback function
g_pRamp = pRamp;
EnumDisplayMonitors( 0, 0, EnumMonitorProc, 0 );
g_pRamp = 0;
}

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker