Using JNA for accessing tooltip from windows

Using JNA for accessing tooltip from windows

i am started experimenting with JNA to access every tooltip from windows.
For this i am sending TTM_GETTOOLINFO message continuously to window.
Below is my code...
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);
}
}
}
But its not working. I am using window 8. I found two version of
commctrl.h on web. One is showing that TTM_GETTOOLINFOA= WM_USER+8
TTM_GETTOOLINFOW= WM_USER+53 and other is showing TTM_GETTOOLINFOA=
WM_USER+9 TTM_GETTOOLINFOW= WM_USER+54. However i tried with every
combination with both SendMessageA and W. So i think there are some
fundamental mistakes. So anyone can plz help me in the same. Accessing
tooltip from JNA.