使用 SetDeviceGammaRamp 调整屏幕亮度
- UID
- 1066743
|
使用 SetDeviceGammaRamp 调整屏幕亮度
//hDC DC句柄,如果为NULL时使用整个屏幕
//wR wG wB 0~255, 默认128
BOOL SetBrightness(HDC hDC, int wR, int wG, int wB)
{
BOOL bRet = FALSE;
HDC hGammDC = hDC? hDC: ::GetDC(NULL);
#pragma pack(push, 8)
typedef struct _tagD3dGammaramp_t
{
WORD red [256];
WORD green[256];
WORD blue [256];
}_D3DGAMMARAMP, *LP_D3DGAMMARAMP;
#pragma pack(pop)
_D3DGAMMARAMP mGamRamp;
memset(&mGamRamp, 0, sizeof(mGamRamp));
for (int iIndex = 0; iIndex < 256; iIndex++)
{
mGamRamp.red[iIndex] = min(65535, iIndex * (wR + 128));
mGamRamp.green[iIndex] = min(65535, iIndex * (wG + 128));
mGamRamp.blue[iIndex] = min(65535, iIndex * (wB + 128));
}
LPVOID lpRamp = &mGamRamp;
bRet = SetDeviceGammaRamp(hGammDC, lpRamp);
if(hDC == NULL && hGammDC)
{
::ReleaseDC(NULL, hGammDC);
}
return bRet;
} |
|
|
|
|
|