//關閉moniter的電源
sendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER,(LPARAM)2);
//打開moniter的電源
sendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER,(LPARAM)-1);
//low power moniter
SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER,(LPARAM)1);
在開始的時候要注冊電源通知消息
HANDLE g_hPowerNotify
GUID GUID_MON_POWER = GUID_MONITOR_POWER_ON;
g_hPowerNotify= RegisterPowerSettingNotification(g_hWnd,&GUID_MON_POWER,DEVICE_NOTIFY_WINDOW_HANDLE):
然後在窗口過程中
//當有電源狀態發生改變時。window會發這個消息出來
//當開機第一次進系統的時候。一般都會進入電源狀態改變的事件。
case WM_POWERBROADCAST:
{
if(wParam==PBT_POWERSETTINGCHANGE)
{
POWERBROADCAST_SETTING* pps= (POWERBROADCAST_SETTING*)lParam;
if(sizeof(DWORD)==pps->DataLength&&pps->PowerSetting ==GUID_MONITER_POWER_ON)
{
g_bLCDPwrOn = pps->Data[0];
}
}
}
//在窗口銷毀中取消注冊
case WM_DESTROY
UnregisterPowerSettingNotification(g_hPowerNotify);
//補充