標籤:鍵盤 style monit des pow 開啟 滑鼠 http turn
好睏,想躺一下,關燈、上床,筆記本的螢幕還亮著,好刺眼,睡不著!
腦子裡出現一個疑問,怎麼用C++寫一個關閉螢幕的小程式呢?
參考了網上已有的例子,最簡化:
1 #include <windows.h>2 3 int main()4 {5 /* The display is being shut off */6 SendMessage(FindWindow(0,0), WM_SYSCOMMAND, SC_MONITORPOWER, 2);7 8 return 0;9 }
執行後,會關閉顯示器的電源,其它的似乎不受影響(暫時沒有驗證)。如果要喚醒螢幕,動動滑鼠,或是敲敲鍵盤就可以了。
關於“WM_SYSCOMMAND message”的參考:https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms646360(v=vs.85).aspx
裡面有關於SC_MONITORPOWER的說明:
-
SC_MONITORPOWER
-
0xF170
|
Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer. The lParam parameter can have the following values:
- -1 (the display is powering on)
- 1 (the display is going to low power)
- 2 (the display is being shut off)
|
SC_MONITORPOWER的作用是用於設定顯示器的狀態。這條指令支援那些帶有節能特性的裝置,比如,由電池供電的個人電腦。
參數lParam的值可以為下列值:
-1 開啟顯示器電源
1 使顯示器進入低功耗模式
2 關閉顯示器的電源
一個小插曲,我用我的筆記本調試可以,能關閉顯示器的電源。但是,我讓我的朋友用台式機測試,實現不了,顯示器關了,緊接著又重開。
關於函數SendMessage()和FindWindow(),暫時沒有看懂,不解釋。
C++ 關閉顯示器