|
- #include
- #include
- #include
- #include
- #include
- static const TCHAR g_szRegKey[] = TEXT("ControlPanel\\BackLight");
- static const TCHAR g_szBatTimeout[] = TEXT("BatteryTimeout");
- static const TCHAR g_szExtTimeout[] = TEXT("ACTimeout");
- static const TCHAR g_szUseBattery[] = TEXT("UseBattery");
- static const TCHAR g_szUseExt[] = TEXT("UseExt");
- UINT ThreadProc(LPVOID ptr)
- {
- HANDLE hUserActive;
- HANDLE hUserInactive;
- HANDLE hRegEvent;
- HKEY hKey;
- DWORD dwBatTimeout = 0;
- DWORD dwExtTimeout = 0;
- DWORD dwUseBattery = 0;
- DWORD dwUseExt = 0;
- hKey = NULL;
- Sleep(2000);
- hUserActive = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("PowerManager/UserActivity_Active"));
- hUserInactive = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("PowerManager/UserActivity_Inactive"));
- RETAILMSG(0, (L"## hUserActive=0x%x hUserInactive=0x%x\r\n", hUserActive, hUserInactive) );
- if(hUserActive && hUserInactive && (RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegKey, 0, 0, &hKey) == ERROR_SUCCESS) )
- {
- HANDLE hEvs[1];
- DWORD dwTimeout;
- HINSTANCE hInst;
- hEvs[0] = hUserActive;
- dwTimeout = INFINITE;
- while(hKey)
- {
- switch(WaitForMultipleObjects(1, hEvs, FALSE, dwTimeout))
- {
- case WAIT_OBJECT_0:
- RETAILMSG(0, (L"## WAIT_OBJECT_0 hEvs[0]=0x%x\r\n", hEvs[0]) );
- if(hEvs[0] == hUserActive)
- {
- dwTimeout = INFINITE;
- hEvs[0] = hUserInactive;
- //lcd on
- LCDON();
- RETAILMSG(0, (L"## hUserActive dwTimeout=%d\r\n", dwTimeout) );
- }
- else
- {
- DWORD dwType, dwSize;
- dwSize = sizeof(DWORD);
- RegQueryValueEx(hKey, g_szBatTimeout, NULL, &dwType, (LPBYTE)&dwBatTimeout, &dwSize);
- RegQueryValueEx(hKey, g_szExtTimeout, NULL, &dwType, (LPBYTE)&dwExtTimeout, &dwSize);
- RegQueryValueEx(hKey, g_szUseBattery, NULL, &dwType, (LPBYTE)&dwUseBattery, &dwSize);
- RegQueryValueEx(hKey, g_szUseExt , NULL, &dwType, (LPBYTE)&dwUseExt , &dwSize);
- RETAILMSG(0, (L"## dwBatTimeout=%d dwExtTimeout=%d dwUseBattery=%d dwUseExt=%d\r\n",
- dwBatTimeout, dwExtTimeout, dwUseBattery, dwUseExt) );
- if(dwUseExt && dwExtTimeout)
- dwTimeout = dwExtTimeout * 1000;
- else if(dwUseBattery && dwBatTimeout)
- dwTimeout = dwBatTimeout * 1000;
- else
- dwTimeout = INFINITE;
- hEvs[0] = hUserActive;
- RETAILMSG(0, (L"## hUserInactive dwTimeout=%d\r\n", dwTimeout) );
- }
- break;
- case WAIT_TIMEOUT:
- RETAILMSG(0, (L"## WAIT_TIMEOUT hEvs[0]=0x%x\r\n", hEvs[0]) );
- if(hEvs[0] == hUserActive)
- {
- //lcd off
- LCDOFF();
- dwTimeout = INFINITE;
- }
- break;
- case WAIT_FAILED:
- RETAILMSG(0, (L"## WAIT_FAILED\r\n"));
- RegCloseKey(hKey);
- hKey = NULL;
- break;
- }
- }
- }
- CloseHandle(hUserActive);
- CloseHandle(hUserInactive);
- CloseHandle(hRegEvent);
- return 0;
- }
- BOOL StartBacklightThread(void)
- {
- //SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- if( CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, NULL, 0, NULL))
- {
- RETAILMSG(1, (TEXT("Display: StartBacklightThread OK\r\n")));
- return TRUE;
- }
- return FALSE;
- }
复制代码 |
|