简体   繁体   English

如何关闭Win8平板电脑的显示

[英]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.

相关问题 如何在通过Win8在XP上运行的C ++窗口中显示HTML? - How do I display HTML in a C++ Window that works on XP through Win8? Win8如何将进程归类为“背景进程”? 我的应用程序可在Win7中运行,但在Win8中不显示用户界面 - How does Win8 classify a process as a “Background Process”? My app works in Win7 but shows no UI in Win8 关闭远程PC上的显示器 - Turn off the display on remote PC 如何检查我的库是否用于Win8 Store应用程序或Win32应用程序? - How to check if my library is used for a Win8 Store app or a Win32 app? 什么是Win编译开关关闭#pragma弃用警告? - What is the Win compile switch to turn off #pragma deprecated warning? 如何关闭异常处理? - How to turn off exception handling? win32,scrollwindowex():如何从向下滚动后消失的“关闭窗口”显示向上区域? - win32, scrollwindowex(): How to display back the up area from “off window” that disappeared after scrolling down? 如何在Win8 / Metro / WinRT中获取DocumentsLibrary的绝对路径? - How do I get the absolute path of DocumentsLibrary in Win8/Metro/WinRT? SetSuspendState()API在Win8中永远不会返回 - SetSuspendState() API never returns in Win8 在win8登录屏幕上运行应用程序 - Run application on win8 login screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM