资源描述:
《vb关闭、开启显示器》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、用VB定时关闭显示器与音箱注意是“关闭”显示器,也即是没有信号,不是弄个纯黑色的窗体,希望两个仪器的关闭代码要分开(便于维护),移动鼠标或按下键盘即要解锁。还请说明实现原理。关闭显示器倒是有API,下列代码可以帮你关闭显示器(是绝对的没有信号),但关闭音箱是没有办法的...为什么呢?因为电脑没有控制音箱电源的线啊..只有音频线...只能控制有声音没声音...如果一定要控制音箱的电源线开关...那么,建议你去学习单片机及电子线路...下列代码可以帮你关闭显示器.PrivateDeclareFunctionCloseScreenFunLib"user32"Alias"SendMess
2、ageA"(ByValhwndAsLong,ByValwMsgAsLong,ByValwParamAsLong,ByVallParamAsLong)AsLongPrivateDeclareFunctionGetForegroundWindowLib"user32"()AsLongPrivateConstWM_SYSCOMMAND=&H112&PrivateConstSC_MONITORPOWER=&HF170&PrivateSubCloseScreenA(ByValsWitchAsBoolean)IfsWitch=TrueThenCloseScreenFunGetForegrou
3、ndWindow,WM_SYSCOMMAND,SC_MONITORPOWER,1&ElseCloseScreenFunGetForegroundWindow,WM_SYSCOMMAND,SC_MONITORPOWER,-1&EndIfEndSubPrivateDeclareFunctionSendScreenMessageLib"user32"_Alias"SendMessageA"_(ByValhwndAsLong,_ByValwMsgAsLong,_ByValwParamAsLong,_lParamAsAny)AsLongPrivateConstMONITOR_ON=-1&P
4、rivateConstMONITOR_LOWPOWER=1&PrivateConstMONITOR_OFF=2&PrivateConstSC_MONITORPOWER=&HF170&PrivateConstWM_SYSCOMMAND=&H112'关闭显示器PublicFunctionMonitorOff(FormAsForm)CallSendScreenMessage(Form.hwnd,WM_SYSCOMMAND,SC_MONITORPOWER,ByValMONITOR_OFF)EndFunction'开启显示器PublicFunctionMonitorOn(FormAsFor
5、m)CallSendScreenMessage(Form.hwnd,WM_SYSCOMMAND,SC_MONITORPOWER,ByValMONITOR_ON)EndFunction'关闭显示器电源:)---深度睡眠PublicFunctionMonitorPowerDown(FormAsForm)CallSendScreenMessage(Form.hwnd,WM_SYSCOMMAND,SC_MONITORPOWER,ByValMONITOR_LOWPOWER)EndFunctionPrivateDeclareFunctionSendScreenMessageLib"user3
6、2"_Alias"SendMessageA"_(ByValhwndAsLong,_ByValwMsgAsLong,_ByValwParamAsLong,_lParamAsAny)AsLongPrivateConstMONITOR_ON=-1&PrivateConstMONITOR_LOWPOWER=1&PrivateConstMONITOR_OFF=2&PrivateConstSC_MONITORPOWER=&HF170&PrivateConstWM_SYSCOMMAND=&H112'关闭显示器PublicFunctionMonitorOff(FormAsForm)CallSen
7、dScreenMessage(Form.hwnd,WM_SYSCOMMAND,SC_MONITORPOWER,ByValMONITOR_OFF)EndFunction'开启显示器PublicFunctionMonitorOn(FormAsForm)CallSendScreenMessage(Form.hwnd,WM_SYSCOMMAND,SC_MONITORPOWER,ByValMONITOR_ON)EndFunction