#AdditionalJar: jna-5.0.0
#AdditionalJar: jna-platform-5.0.0
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
Dim jo As JavaObject
jo.InitializeNewInstance("b4j.example.main$TurnOffMonitor", Null)
jo.RunMethod("turnOff", Null)
Sleep(3000)
jo.RunMethod("turnOn", Null)
End Sub
Sub Button1_Click
xui.MsgboxAsync("Hello World!", "B4X")
End Sub
#if JAVA
import com.sun.jna.Native;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.win32.StdCallLibrary;
public static class TurnOffMonitor {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int SC_MONITORPOWER = 0xF170;
int SC_MONITOR_OFF = 2;
int SC_MONITOR_ON = -1;
LRESULT SendMessageA(HWND paramHWND, int paramInt, WPARAM paramWPARAM,
LPARAM paramLPARAM);
LRESULT SendMessageA(HWND paramHWND, int paramInt, int paramInt2,
LPARAM paramLPARAM);
}
private static final long SLEEP_TIME = 4 * 1000; // 4 seconds
public static void turnOff () {
final User32 user32 = User32.INSTANCE;
user32.SendMessageA(WinUser.HWND_BROADCAST, WinUser.WM_SYSCOMMAND,
User32.SC_MONITORPOWER, new LPARAM(User32.SC_MONITOR_OFF));
}
public static void turnOn () {
final User32 user32 = User32.INSTANCE;
user32.SendMessageA(WinUser.HWND_BROADCAST, WinUser.WM_SYSCOMMAND,
User32.SC_MONITORPOWER, new LPARAM(User32.SC_MONITOR_ON));
}
}
#End If