我开始尝试使用 JNA 从 Windows 访问每个工具提示。为此,我不断向窗口发送 TTM_GETTOOLINFO 消息。下面是我的代码...
public class Test {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
HWND GetForegroundWindow(); // add this
int SendMessageA(HWND hwnd, int msg, int num1, TOOLINFO f );
// int SendMessageW(HWND hwnd, int msg, int num1, TOOLINFO f );
}
public class TOOLINFO extends Structure
{
public int cbSize;
public int uFlags;
public HWND hwnd;
public UINT_PTR uId;
public RECT rect;
public HINSTANCE hinst;
public char [] lpszText;
TOOLINFO()
{
lpszText = new char[512];
}
}
public static void main(String[] args)
{
new Test().go();
}
public void go()
{
TOOLINFO tt = new TOOLINFO();
int WM_USER = 0x0400;
HWND hwnd ;
int i=0;
while(true)
{
hwnd= User32.INSTANCE.GetForegroundWindow();
try
{
i=User32.INSTANCE.SendMessageA(hwnd,WM_USER+8, 0, tt);
}
catch(Exception ex)
{
ex.printStackTrace();
}
if(i!=0)
System.out.println("Tooltip :"+tt.lpszText);
}
}
}
但它不起作用。我正在使用窗口 8。我在网上找到了两个版本的 commctrl.h。一个显示 TTM_GETTOOLINFOA= WM_USER+8 TTM_GETTOOLINFOW= WM_USER+53 另一个显示 TTM_GETTOOLINFOA= WM_USER+9 TTM_GETTOOLINFOW= WM_USER+54。但是,我尝试了 SendMessageA 和 W 的每种组合。所以我认为存在一些基本错误。所以任何人都可以帮助我。从 JNA 访问工具提示。
public class JnaTest2 {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
HWND GetForegroundWindow(); // add this
int SendMessageW(HWND hwnd,int msg ,WPARAM w,TOOLINFOW lparam);
}
public class TOOLINFOW extends Structure
{
public int cbSize;
public int uFlags;
public HWND hwnd;
public UINT_PTR uId;
public RECT rect;
public HINSTANCE hinst;
public Pointer pszText = new Memory(512);
LPARAM l;
Pointer lpReserved=null;
}
public static void main(String[] args)
{
new JnaTest2().go();
}
public void go()
{
int WM_USER = 0x0400;
TOOLINFOW tt = new TOOLINFOW();
tt.cbSize=tt.size();
System.out.println(tt.size());
HWND hwnd ;
int j=0;
while(true)
{
hwnd=User32.INSTANCE.GetForegroundWindow();
tt.hwnd=hwnd;
try
{
j=User32.INSTANCE.SendMessageW(hwnd,WM_USER+53,new WPARAM(0),tt);
}
catch(Exception ex)
{
ex.printStackTrace();
}
if(j!=0)
System.out.println("Tooltip :"+tt.pszText.getString(0));
}
}
}