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.
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));
}
}
}
TTM_GETTOOLINFOW
.SendMessageW
.hWnd
and cbSize
fields of TOOLINFO
. lpszText
must be of pointer type, not an inline array. You can use Memory
, with a field type of Pointer
. Make sure it's big enough.lParam
(type LPARAM
) and lpReserved
(type Pointer
) fields.Edit your question to show how you implemented each of these things and the corresponding result.
EDIT
Check Native.getLastError()
to see if the method call resulted in an error. It won't throw an exception.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다