....
#AdditionalJar: jna-4.2.1
#AdditionalJar: jna-platform-4.2.1
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Dim inline As JavaObject
End Sub
Sub AppStart (Form1 As Form, Args() As String)
inline = Me
MainForm = Form1
MainForm.SetFormStyle("UNIFIED")
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
' test if Notepad is running, if not attempt to start it using shell
inline.RunMethod("isRunning",Array("Notepad"))
End Sub
Sub startProcess(name As String)
Dim sh As Shell
sh.Initialize("",name,Null)
sh.Run(-1)
End Sub
#if java
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
public static void isRunning(String progName) throws Exception {
HWND hwnd = User32.INSTANCE.FindWindow(progName,null); // program name
if (hwnd == null) {
System.out.println(progName + " is not currently running. Will attempt to start it.");
_startprocess(progName); // can use this shortcut to b4j sub as it's in same class
}
else
{
System.out.println(progName + " is currently running, giving it focus");
User32.INSTANCE.ShowWindow(hwnd, 9 ); // SW_RESTORE
User32.INSTANCE.SetForegroundWindow(hwnd); // bring to front
}
}
#end if