Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KeypadLedControl.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <windows.h>
- // From MSDN: http://msdn.microsoft.com/en-us/library/ms838354.aspx
- #define QUERYESCSUPPORT 8
- #define SETPOWERMANAGEMENT 6147
- #define GETPOWERMANAGEMENT 6148
- typedef struct VIDEOPOWER_MANAGEMENT {
- ULONG Length;
- ULONG DPMSVersion;
- ULONG PowerState;
- } VIDEO_POWER_MANAGEMENT, *PVIDEO_POWER_MANAGEMENT;
- int _tmain(int argc, _TCHAR* argv[])
- {
- // Create an event for ourselves, so that we can be turned off as well
- HANDLE appEvent = CreateEvent(NULL, TRUE, FALSE, L"KeypadLedControlApp");
- if (appEvent == NULL)
- {
- MessageBox(NULL, L"Couldn't create an event for ourselves", L"Error", MB_OK);
- return 1;
- }
- // If the app is already running, we set the event so that it will close itself.
- if (GetLastError() == ERROR_ALREADY_EXISTS)
- {
- SetEvent(appEvent);
- CloseHandle(appEvent);
- return 1;
- }
- // Get the keyped led event (this one is used for Leo at least)
- HANDLE iconEvent = CreateEvent(NULL, TRUE, FALSE, L"IconLedOnEvent");
- if (iconEvent == NULL)
- {
- // Oops, error creating the event?
- MessageBox(NULL, L"Couldn't create the 'IconLedOnEvent' keypad light event", L"Error", MB_OK);
- return 1;
- }
- if (GetLastError() != ERROR_ALREADY_EXISTS)
- {
- // This even didn't exist yet. Let's see if we can try another event (it's IconLedEvent for Rhodium)
- CloseHandle(iconEvent);
- iconEvent = CreateEvent(NULL, TRUE, FALSE, L"IconLedEvent");
- if (iconEvent == NULL)
- {
- MessageBox(NULL, L"Couldn't create the 'IconLedEvent' keypad light event", L"Error", MB_OK);
- return 1;
- }
- if (GetLastError() != ERROR_ALREADY_EXISTS)
- {
- // This event didn't exist either.
- MessageBox(NULL, L"Sorry, this device is not supported it seems", L"Error", MB_OK);
- CloseHandle(iconEvent);
- return 1;
- }
- }
- // Check if the driver supports power management information
- HDC gdc = GetDC(NULL);
- int iESC = GETPOWERMANAGEMENT;
- if (ExtEscape(gdc, QUERYESCSUPPORT, sizeof(int), (LPCSTR)&iESC, 0, NULL) == 0)
- {
- MessageBox(NULL, L"This device does not support checking for LCD state", L"Error", MB_OK);
- CloseHandle(iconEvent);
- ReleaseDC(NULL, gdc);
- return 1;
- }
- VIDEO_POWER_MANAGEMENT pm;
- pm.Length = sizeof(pm);
- int ret;
- while (true)
- {
- // Get current power management information
- ret = ExtEscape(gdc, GETPOWERMANAGEMENT, 0, NULL, pm.Length, (LPSTR)&pm);
- // If the LCD is on, set the event so that the lights go on
- if (pm.PowerState == 1)
- {
- SetEvent(iconEvent);
- }
- // We'll keep on running this app as long as the event hasn't been set (by starting this app again)
- if (WaitForSingleObject(appEvent, 8000) != WAIT_TIMEOUT)
- {
- break;
- }
- }
- // Cleanup
- ReleaseDC(NULL, gdc);
- CloseHandle(iconEvent);
- CloseHandle(appEvent);
- return 0;
- }
Add Comment
Please, Sign In to add comment