7,655
社区成员
发帖
与我相关
我的任务
分享
HKEY hKey;
LPCWSTR lpTimeOutKey = L"\\ControlPanel\\BackLight";
if (RegOpenKeyEx(HKEY_CURRENT_USER, lpTimeOutKey ,0, 0, &hKey)==ERROR_SUCCESS)
{
DWORD data = 7-lightLv; \\lightLv为亮度级数
if (RegSetValueEx(hKey,L"Brightness",0,REG_DWORD,(CONST BYTE*)&data,sizeof(DWORD)) != ERROR_SUCCESS)
{
MessageBox(NULL,_T("失败"),_T("Faild"),MB_OK);
}
}
RegCloseKey(hKey);
// 开关灯的代码,来自MSDN
// IN BOOL fBacklightOn - TRUE to keep the backlight on.
void SetBacklightRequirement(BOOL fBacklightOn)
{
// The name of the backlight device.
TCHAR tszBacklightName[] = TEXT("BKL1:");
static HANDLE s_hBacklightReq = NULL;
if (fBacklightOn)
{
if (NULL == s_hBacklightReq)
{
// Turn the backlight on by setting the requirement that the backlight device
// must remain in device state D0 (full power). Replace D0 with D4 (zero power) to
// turn the backlight off.
s_hBacklightReq = SetPowerRequirement(tszBacklightName, D0, POWER_NAME, NULL, 0);
if (!s_hBacklightReq)
RETAILMSG(1, (L"SetPowerRequirement failed: %X\n", GetLastError()));
}
}
else
{
if (s_hBacklightReq)
{
if (ERROR_SUCCESS != ReleasePowerRequirement(s_hBacklightReq))
RETAILMSG(1, (L"ReleasePowerRequirement failed: %X\n", GetLastError()));
s_hBacklightReq = NULL;
}
}
}