Sub Button1_Click
Dim jo As JavaObject=Me
jo.RunMethod("taskbar",Null)
End Sub
#if java
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.RECT;
import com.sun.jna.platform.win32.WinDef.HWND;
public static void taskbar() {
User32 user32 = User32.INSTANCE;
HWND hWnd = user32.FindWindow("Shell_TrayWnd", null);
if (hWnd != null) {
RECT rect = new RECT();
user32.GetWindowRect(hWnd, rect);
int x = rect.left;
int y = rect.top;
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
BA.Log("Task Bar Location: (" + x + ", " + y +...
YesWhat is the postion of the TaskBar you meant, is it on the top,left right or bottom of the screen?
I need to get the taskbar height, and position....
Sub Button1_Click
Dim jo As JavaObject=Me
jo.RunMethod("taskbar",Null)
End Sub
#if java
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.RECT;
import com.sun.jna.platform.win32.WinDef.HWND;
public static void taskbar() {
User32 user32 = User32.INSTANCE;
HWND hWnd = user32.FindWindow("Shell_TrayWnd", null);
if (hWnd != null) {
RECT rect = new RECT();
user32.GetWindowRect(hWnd, rect);
int x = rect.left;
int y = rect.top;
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
BA.Log("Task Bar Location: (" + x + ", " + y + ")");
BA.Log("Task Bar Size: " + width + "x" + height);
}
}
#End If
'Right
Task Bar Location: (1827, 0)
Task Bar Size: 93x1080
'Top
Task Bar Location: (0, 0)
Task Bar Size: 1920x40
'Left
Task Bar Location: (0, 0)
Task Bar Size: 93x1080
'Bottom
Task Bar Location: (0, 1040)
Task Bar Size: 1920x40
Amongst some results I found, this seem to be the most complete and pertinent piece of code:You can probably help getting this answered by posting some links to code examples found on the internet that give those values.
public enum Location {
TOP, RIGHT, BOTTOM, LEFT;
}
private static final class Taskbar {
public final Location location;
public final int width, height;
private Taskbar(Location location, int width, int height) {
this.location = location;
this.width = width;
this.height = height;
}
public static Taskbar getTaskbar() {
Rectangle other = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getMaximumWindowBounds();
return new Taskbar(other.x != 0 ? Location.TOP
: (other.y != 0 ? Location.LEFT
: (other.width == IFrame.width ? Location.BOTTOM
: Location.RIGHT)), IFrame.width
- other.width, IFrame.height - other.height);
}
}
You can determine the position based on coordinates and aspect ratioB4X:'Right Task Bar Location: (1827, 0) Task Bar Size: 93x1080 'Top Task Bar Location: (0, 0) Task Bar Size: 1920x40 'Left Task Bar Location: (0, 0) Task Bar Size: 93x1080 'Bottom Task Bar Location: (0, 1040) Task Bar Size: 1920x40
Using your code I'm getting this error:You can do that using jna, the code is below
LogB4X:Sub Button1_Click Dim jo As JavaObject=Me jo.RunMethod("taskbar",Null) End Sub #if java import com.sun.jna.platform.win32.User32; import com.sun.jna.platform.win32.WinDef.RECT; import com.sun.jna.platform.win32.WinDef.HWND; public static void taskbar() { User32 user32 = User32.INSTANCE; HWND hWnd = user32.FindWindow("Shell_TrayWnd", null); if (hWnd != null) { RECT rect = new RECT(); user32.GetWindowRect(hWnd, rect); int x = rect.left; int y = rect.top; int width = rect.right - rect.left; int height = rect.bottom - rect.top; BA.Log("Task Bar Location: (" + x + ", " + y + ")"); BA.Log("Task Bar Size: " + width + "x" + height); } } #End If
B4X:'Right Task Bar Location: (1827, 0) Task Bar Size: 93x1080 'Top Task Bar Location: (0, 0) Task Bar Size: 1920x40 'Left Task Bar Location: (0, 0) Task Bar Size: 93x1080 'Bottom Task Bar Location: (0, 1040) Task Bar Size: 1920x40
[IDE message - 3:07:29]
An error occurred.
src\b4j\example\b4xmainpage.java:4: error: package com.sun.jna.platform.win32 does not exist
import com.sun.jna.platform.win32.User32;
^
Note: src\b4j\example\main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
only showing the first 1 errors, of 8 total; use -Xmaxerrs if you would like to see more
javac 19.0.2
The simplest way is to return a JSON string and then put them into a map.The code logs the values, but how do I retrieve them so I can use them? My Java knowledge is almost limited to copy/paste
Sub Button1_Click
Dim jo As JavaObject=Me
Dim s As String=jo.RunMethod("taskbar",Null)
Dim m As Map=s.As(JSON).ToMap
Log(m)
End Sub
#if java
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.RECT;
import com.sun.jna.platform.win32.WinDef.HWND;
public static String taskbar() {
User32 user32 = User32.INSTANCE;
HWND hWnd = user32.FindWindow("Shell_TrayWnd", null);
if (hWnd != null) {
RECT rect = new RECT();
user32.GetWindowRect(hWnd, rect);
int x = rect.left;
int y = rect.top;
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
return "{\"x\":"+x+",\"y\":"+y+",\"w\":"+width+",\"h\":"+height+"}";
}
return null;
}
#End If