我正在创建一个程序,我在其中获得焦点窗口标题和特定窗口标题的进程ID。一切顺利。但是在行
Pointer zero=new Pointer(0);
有一个警告显示"指针(长)在com.sun.jna.Pointer中不公开;无法从外部包裹访问。" 。我没有得到任何解决方案来解决它。请帮帮我。
public class Main extends SecurityManager
{
public static int brojac = 0;
public interface User32 extends StdCallLibrary
{
User32 instance = (User32) Native.loadLibrary("user32", User32.class);
HWND GetForegroundWindow(); // add this
int GetWindowTextA (HWND hWnd, byte[] lpString, int nMaxCount);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetWindowThreadProcessId(HWND hwnd, IntByReference pid);
}
public interface Kernel32 extends StdCallLibrary
{
Kernel32 INSTANCE = (Kernel32)Native.loadLibrary("kernel32", Kernel32.class);
public Pointer OpenProcess(int dwDesiredAccess, boolean bInheritHandle, int dwProcessId);
public int GetTickCount();
};
public interface psapi extends StdCallLibrary
{
psapi INSTANCE = (psapi)Native.loadLibrary("psapi", psapi.class);
int GetModuleFileNameExA (Pointer process, Pointer hModule, byte[] lpString, int nMaxCount);
};
public static String getModuleFilename(HWND hwnd)
{
byte[] exePathname = new byte[512];
Pointer zero = new Pointer(0);
IntByReference pid = new IntByReference();
User32.instance.GetWindowThreadProcessId(hwnd, pid);
System.out.println("PID is " + pid.getValue());
Pointer process = Kernel32.INSTANCE.OpenProcess(1040, false, pid.getValue());
int result = psapi.INSTANCE.GetModuleFileNameExA(process, zero, exePathname, 512);
System.out.println("===========module is " + result);
String text = Native.toString(exePathname).substring(0, result);
return text;
}
public static void main(String[] args) throws InterruptedException
{
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];
HWND hwnd = User32.instance.GetForegroundWindow(); // then you can call it!
User32.instance.GetWindowTextA(hwnd, windowText, 1024);
String wtext=(Native.toString(windowText));
System.out.println("Found window with text===" + hWnd + ", total=== " + ++count
+ " Text:== " + wtext);
wtext = getModuleFilename(hWnd);
System.out.println("############## " + wtext);
return true;
} }, null);
}
}
答案 0 :(得分:0)
我无法重现你的警告;使用JNA版本4.1.0代码工作预期。虽然在“找到带文本的窗口”开头的第二条消息中调用hWnd.toString()
并没有意义(隐式)。