如何在Java应用程序中打开和关闭监视器? [英] How do you turn on and off a monitor from within a Java application?

查看:193
本文介绍了如何在Java应用程序中打开和关闭监视器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java应用程序中打开和关闭监视器?

How do you turn on and off a monitor from within a Java application?

如果你想知道为什么,这是一个自助服务终端风格的应用程序,它会非常适合在晚上关闭显示器。是的,您可以在机器的屏幕保护程序设置中执行此操作,但以编程方式执行此操作并避免必须在每台计算机上进行配置将非常棒。

In case you're wondering why, this is a kiosk style application where it would be great to turn off the monitors at night. Yes you can do it within the screensaver settings of the machine, but it would be great to do it programatically and avoid having to configure it on each machine.

推荐答案

假设您在Windows上部署Java应用程序,可以使用此WIN32API函数:

Assuming you deploy your Java Applications on Windows, you can use this WIN32API functions:

// turn off monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2); 

// turn on monitor
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);    

然后你写一点 C-JNI包装器用于调用上述 SendMessage 的函数,并使用小包装器从Java关闭监视器。

Then you write a little C-JNI wrapper to functions that call the mentioned SendMessage and use the little wrapper to turn off the monitor from Java.

这篇关于如何在Java应用程序中打开和关闭监视器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆