且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2021-07-15 15:45:04

假设您在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.