|
我用下面的这个代码可以让显示器关闭,用的是 sendmessage,但是我却无法监听到这一事件,怎么回事?如果有知道的帮忙解答下,谢谢。
按道理说,显示器在关闭时候,会广播这个消息,我的程序应该能够接受到这个消息才对,可是Notify这个程序一直不执行。
参考此帖子:http://www.autoitx.com/forum.php?mod=viewthread&tid=38887
关闭显示器的代码:Global Const $lciWM_SYSCommand = 274
Global Const $lciSC_MonitorPower = 61808
Global Const $lciPower_Off = 2
Global Const $lciPower_On = -1
Global $MonitorIsOff = False
HotKeySet("{F11}", "_Monitor_OFF")
HotKeySet("{F10}", "_Monitor_ON")
HotKeySet("{Esc}", "_Quit")
While 1
Sleep(10)
WEnd
Func _Monitor_ON()
$MonitorIsOff = False
Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
DllCall('user32.dll', 'int', 'SendMessage', _
'hwnd', $Progman_hwnd, _
'int', $lciWM_SYSCommand, _
'int', $lciSC_MonitorPower, _
'int', $lciPower_On)
EndFunc
Func _Monitor_OFF()
$MonitorIsOff = True
Local $Progman_hwnd = WinGetHandle('[CLASS:Progman]')
While $MonitorIsOff = True
DllCall('user32.dll', 'int', 'SendMessage', _
'hwnd', $Progman_hwnd, _
'int', $lciWM_SYSCommand, _
'int', $lciSC_MonitorPower, _
'int', $lciPower_Off)
_IdleWaitCommit(0)
Sleep(20)
WEnd
EndFunc
Func _IdleWaitCommit($idlesec)
Local $iSave, $LastInputInfo = DllStructCreate ("uint;dword")
DllStructSetData ($LastInputInfo, 1, DllStructGetSize ($LastInputInfo))
DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
Do
$iSave = DllStructGetData ($LastInputInfo, 2)
Sleep(60)
DllCall ("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr ($LastInputInfo))
Until (DllStructGetData ($LastInputInfo, 2)-$iSave) > $idlesec Or $MonitorIsOff = False
Return DllStructGetData ($LastInputInfo, 2)-$iSave
EndFunc
Func _Quit()
_Monitor_ON()
Exit
EndFunc
我的监听代码:#include <GUIConstants.au3>
#include <FILE.AU3>
#include <date.au3>
#include <process.au3>
#include-once
Global $WM_SYSCOMMAND = 0x0112
Global $SC_CLOSE = 0xF060
Global $SC_CONTEXTHELP = 0xF180
Global $SC_DEFAULT = 0xF160
Global $SC_HOTKEY = 0xF150
Global $SC_HSCROLL = 0xF080
Global $SCF_ISSECURE = 0x00000001
Global $SC_KEYMENU = 0xF100
Global $SC_MAXIMIZE = 0xF030
Global $SC_MINIMIZE = 0xF030
Global $SC_MONITORPOWER = 0xF170
Global $SC_MOVE = 0xF010
Global $SC_NEXTWINDOW = 0xF040
Global $fp_log = @ScriptDir & "\Test.log"
$hGUI = GUICreate("Test", 100, 100,1,1)
GUIRegisterMsg(274, "Notify")
While 1
Sleep(100)
WEnd
Func Notify($hWnd, $Msg, $wParam, $lParam)
Select
Case $wParam = $SC_MONITORPOWER
_FileWriteLog($fp_log,"$lParam" & $lParam & @CRLF)
Case $wParam = $SC_CLOSE
_FileWriteLog($fp_log,"Closes the window" & @CRLF)
Case
_FileWriteLog($fp_log,"Changes the cursor to a question mark with a pointer." & @CRLF)
Case
_FileWriteLog($fp_log,"Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate." & @CRLF)
Case Else
_FileWriteLog($fp_log,"unknown Power settings"& @CRLF)
EndSelect
EndFunc
|
|