Window handle in java

I am working on a desktop application in java and I want a handle to another window created in some other language running in a window in some process. I know its name, name, image name and other details. I cannot find an API for this purpose.

Please let me know if there is any API or library to achieve this. We can easily perform this action in C ++:

hwnd = FindWindow(NULL,(LPCWSTR)"XYZ"); 
+4
source share
2 answers

The simplest solution is JNA . FindWindow example:

 WinDef.HWND hWnd = User32.INSTANCE.FindWindow("className", "windowName"); 
+5
source

Use JNI to get this information. Basically, JNI allows you to create a C ++ dll that implements this function, and you return a value for the Java application. If you want to use this in an applet, you will have to sign the applet (otherwise, do not use the DLL).

Check this out: http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

+1
source

Source: https://habr.com/ru/post/1497103/


All Articles