B4J Question How to get control's handle (hwnd)?

einstalker

New Member
Hi,

I was wondering if I could get the handle (hwnd) of a control in an UI app? I saw some java code snippets but was unable to use them.

Perhaps something like this:

B4X:
Dim hwd as int = panel1.Handle

TIA.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to get the form handle:
B4X:
Dim jo As JavaObject = Me
Dim handle As Long = jo.RunMethod("getWindowPointer", Array(MainForm))
 Log(handle)


#if JAVA
import java.lang.reflect.Method;
import com.sun.javafx.tk.TKStage;
public static long getWindowPointer(anywheresoftware.b4j.objects.Form form) throws Exception{
  TKStage tkStage = form.stage.impl_getPeer();
  Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow" );
  getPlatformWindow.setAccessible(true);
  Object platformWindow = getPlatformWindow.invoke(tkStage);
  Method getNativeHandle = platformWindow.getClass().getMethod( "getNativeHandle" );
  getNativeHandle.setAccessible(true);
  Object nativeHandle = getNativeHandle.invoke(platformWindow);
  return (Long) nativeHandle;
}
#end if

Based on this answer: http://stackoverflow.com/questions/...-the-window-handle-hwnd-for-a-stage-in-javafx
 
Upvote 0
Top