|
我在调整背光的亮度,写了几个函数,一个是读注册表,一个是写注册表,一个是设置背光亮度,
读注册表的程序如下:
- LONG regStatus;
- DWORD valLen;
- DWORD valType;
- HKEY hregBL;
-
- regStatus = RegOpenKeyEx(HKEY_CURRENT_USER, RK_CONTROLPANEL_BACKLIGHT,0, 0, &hregBL);
- if (regStatus!=ERROR_SUCCESS)
- {
- RETAILMSG(1,(TEXT("Backlight:RegOpenKeyEx(HLM\\%s) failed!!\r\n"),RK_CONTROLPANEL_BACKLIGHT));
- //return regStatus;
- }
- valLen = sizeof(DWORD);
- regStatus = RegQueryValueEx(hregBL, TEXT("Brightness"), NULL,&valType, (PBYTE)&pBrightness, &valLen);
- RETAILMSG(1,(TEXT("pBrightness=0x%x\r\n"),pBrightness));
-
- if (regStatus!=ERROR_SUCCESS)
- {
- pBrightness = 0xa;
- }
- RETAILMSG(1,(TEXT("pBrightness1=0x%x\r\n"),pBrightness));
- RegCloseKey(hregBL);
复制代码
写注册表的程度如下:
- void SetBacklightRegs(void)
- {
- LONG regStatus;
- HKEY hregBL;
-
- regStatus = RegOpenKeyEx(HKEY_CURRENT_USER, RK_CONTROLPANEL_BACKLIGHT, 0, 0, &hregBL);
- if (regStatus!=ERROR_SUCCESS)
- {
- RETAILMSG(1,(TEXT("Backlight:RegOpenKeyEx(HLM\\%s) failed!!\r\n"),RK_CONTROLPANEL_BACKLIGHT));
- //return regStatus;
- }
- RegSetValueEx(hregBL,TEXT("Brightness"),0,REG_DWORD,(const BYTE *)&pBrightness,sizeof(DWORD));
- RegCloseKey(hregBL);
- }
复制代码
设置背光时,我是先通过读注册表读出pBrightness的值,然后改变,然后再写回去。写的时候就会出错,系统会直接halt,如果不写回去,就不会出错,但是由于每次设置都是先读出来,所以如果不写回去的话,每次读出来的都还是默认值,背光只能改变一次。
请大家帮忙看一下,我写回去的代码有问题吗?
非常感谢!
|
|