2017-06-14 31 views
-2

下,屏幕保护程序,我想知道如何在Windows 8的(嵌入式版本)或Windows 10中断屏幕保护程序,因为我的项目的一个窗口(C#)只在正常状态下运行,否则在屏幕保护程序下运行将会出错。所以我想在这个窗口弹出之前中断屏幕保护程序。如何中断Windows 8的

我已经研究了一些解决方案和想法,包括如下,

  • 一个。移动鼠标(使用的USER32的mouse_event API)
  • 湾发送密钥(也使用user32的api)
  • c。杀死屏幕保护程序。

一个& B的虽然这两种方式我都尝试过,并在Windows 10效果不错,但在Windows 8(嵌入式版本)没有工作,所以目前我只专注于C的方式,讲述方​​式三我找遍了如下链接,

https://support.microsoft.com/en-us/help/140723/how-to-force-a-screen-saver-to-close-once-started-in-windows-nt,-windows-2000,-and-windows-server-2003

https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C

但上述链接仍然没有在Windows 10和Windows 8(嵌入式版本)的工作,哪位高手给我一些建议吗?提前致谢。

回答

1

查看非托管API函数GetSystemPowerStatusSetThreadExecutionState。使用(线程)定时器,您可以定期更新状态,例如从一个类的属性,并通知系统有关您的要求。如果您的应用程序可能允许或不允许屏幕保护程序,这取决于它的操作状态,这很有用。

public class PowerManager : IDisposable 
{ 
    [Flags] 
    public enum ExecutionStateEnum : uint 
    { 
    LetTheSystemDecide = 0x00, 
    SystemRequired  = 0x01, 
    SystemDisplayRequired = 0x02, 
    UserPresent   = 0x04, 
    Continuous   = 0x80000000, 
    } 

    [DllImport("kernel32")] 
    private static extern uint SetThreadExecutionState(ExecutionStateEnum esFlags); 

    public PowerManager() {} 

    public Update(ExecutionStateEnum state) 
    { 
    SetThreadExecutionState(state); 
    } 
} 

更新:

然后调用PowerManager.Update(ExecutionStateEnum.SystemDisplayRequired)禁用屏幕保护程序,或致电PowerManager.Update(ExecutionStateEnum.LetTheSystemDecide)恢复默认的系统行为(允许屏幕保护程序)。 如果从定时器回调中定期调用该方法,请根据配置的屏幕保护程序超时调整定时器时间间隔。

+0

它真的有用!非常感谢你! –