2008 01 22 24 55 在windows下寫程式關閉螢幕


在Turbo C++ Explorer下只需要在WinMain裡加一行,
SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER, 2);
HWND_BROADCAST 在 windows.h 裡定義 -1。
不過,是不是用 HWND_BROADCAST 這個 Handle 去送,
事實上是沒有影響的。
我也用過Application->Handle都可以work。
根據 MSDN 裡面的描述,
SC_MONITORPOWER
Setsthe state of the display. This command supports devices that havepower-saving features, such as a battery-powered personal computer.

The lParam parameter can have the following values:

1 - the display is going to low power

2 - the display is being shut off


而網路上是認為 -1 是 turn on display 。
雖然MSDN裡面並沒有說明.

Ref: http://epasser.aydc.com.cn/tw/article/adp/2-10-6/content17232.html
Ref: http://msdn2.microsoft.com/en-us/library/ms646360(VS.85).aspx

PS: 在關掉螢幕之後,可以call這個API
BOOL WINAPI LockWorkStation(void);
順便把螢幕給鎖起來。