[英]How to turn off the display of a Win8 tablet
Is there a way to turn off the display of a Win8 Tablet without putting the tablet in sleep mode? 有没有一种方法可以关闭Win8 Tablet的显示而不将其置于睡眠模式?
I use following C++ code, but this code puts the tablet in sleep mode: 我使用以下C ++代码,但此代码将平板电脑置于睡眠模式:
const LPARAM OFF = 2;
// const LPARAM LOW = 1;
const LPARAM ON = -1;
LPARAM state = 0;
if (monitorOn) state = ON; // set monitor on
else state = OFF; // set monitor off
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, state);
We need to create a new VNC connection while the display is off. 显示屏关闭时,我们需要创建一个新的VNC连接。 But we can't do that while the Tablet is in sleeping mode. 但是当平板电脑处于睡眠模式时,我们无法做到这一点。 Also the monitor on functionality (see code above) doesn't work in sleeping mode... 同样,有关功能的监视器(请参见上面的代码)在睡眠模式下不起作用...
Anybody knows how I can only turn off the display of a Win8 Tablet? 谁知道我只能关闭Win8 Tablet的显示吗?
You can try using the Power Management API to keep the computer on when it is put to sleep. 您可以尝试使用电源管理API将计算机置于睡眠状态。 I'm not sure if you can still connect using VNC when the computer is in this state, but it's worth a try. 我不确定在计算机处于这种状态时是否仍可以使用VNC进行连接,但是值得尝试。
#include <atlbase.h>
#include <atlutil.h>
#include <powrprof.h>
#pragma comment(lib, "PowrProf.lib")
#include <iostream>
using namespace std;
int main()
{
try
{
POWER_REQUEST_CONTEXT context;
context.Version = POWER_REQUEST_CONTEXT_VERSION;
context.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING;
context.Reason.SimpleReasonString = L"Turn screen off";
CHandle powerRequest(PowerCreateRequest(&context));
if(powerRequest == INVALID_HANDLE_VALUE)
AtlThrowLastWin32();
if(!PowerSetRequest(powerRequest, PowerRequestAwayModeRequired))
AtlThrowLastWin32();
if(!SetSuspendState(FALSE, FALSE, FALSE))
AtlThrowLastWin32();
if(!PowerSetRequest(powerRequest, PowerRequestAwayModeRequired))
AtlThrowLastWin32();
return 0;
}
catch (const CAtlException &e)
{
wcout << "Error: " << AtlGetErrorDescription(e).GetString() << endl;
return e.m_hr;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.