int currentBrightness = 128; // 全局的亮度,初始化为正常亮度值128
int SetGamma(int bright)
{
void * lpGamma = NULL;
int iArrayValue;
WORD gMap[3][256] = {0};
lpGamma = &gMap;
HDC hdc = ::GetDC(NULL);
if (NULL == hdc)
return -1;
for (int i = 0; i < 256; i++)
{
iArrayValue = i * (bright + 128);
if (iArrayValue > 65535)
iArrayValue = 65535;
gMap[0][i] =
gMap[1][i] =
gMap[2][i] = (WORD)iArrayValue;
}
if (FALSE == SetDeviceGammaRamp(hdc, lpGamma))
return -2;
return 0;
}
// 调节屏幕亮度 wBrightness = 1 增加%20亮度, = 2 减少, = 0 正常亮度
int NativeSysOpt::setBrightness( int wBrightness)
{
if(wBrightness == 1)
{
currentBrightness = currentBrightness + 20;
printf("currentBrightness add 20 \n");
}
else if(wBrightness == 2)
{
currentBrightness = currentBrightness - 20;
printf("currentBrightness reduce 20 \n");
}
else if(wBrightness == 0)
{
currentBrightness = 128;
printf("currentBrightness is normal \n");
}
SetGamma(currentBrightness);//128是正常亮度
return 0;
}