Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The latest version of JNA has had some changes that should fix this (as one of the authors of JNA, Luke Quinane, states <a href="https://stackoverflow.com/a/6672729/522444">here</a>). If you use the latest version and check the <a href="http://twall.github.com/jna/3.3.0/javadoc/index.html?index-all.html" rel="nofollow noreferrer">JNA API</a>, you'll see that the WinUser.WNDENUMPROC interface's method actually uses WinDef.HWND as its parameter, not long or int.</p> <p>For example:</p> <pre><code>import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.platform.win32.WinUser; import com.sun.jna.platform.win32.WinUser.WNDENUMPROC; import com.sun.jna.win32.StdCallLibrary; public class TryWithHWND { public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg); int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount); } public static void main(String[] args) { final User32 user32 = User32.INSTANCE; user32.EnumWindows(new WNDENUMPROC() { int count = 0; @Override public boolean callback(HWND hWnd, Pointer arg1) { byte[] windowText = new byte[512]; user32.GetWindowTextA(hWnd, windowText, 512); String wText = Native.toString(windowText); // get rid of this if block if you want all windows regardless of whether // or not they have text if (wText.isEmpty()) { return true; } System.out.println("Found window with text " + hWnd + ", total " + ++count + " Text: " + wText); return true; } }, null); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload