Using JNA for accessing tooltip from windows

Satyajeet

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));

    }
}

}

technomage
  • Use TTM_GETTOOLINFOW.
  • Use SendMessageW.
  • Initialize the 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.
  • You are missing 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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Accessing partition created on Linux from Windows

분류에서Dev

Accessing winreg from jython

분류에서Dev

Accessing the user folder from a previous Windows installation (content on a read-only image)

분류에서Dev

Accessing Ubuntu guest (VirtualBox) node.js server from Windows host

분류에서Dev

Accessing children of second pivot item from code behind with their x:Name returns null in Windows Phone 8.1

분류에서Dev

404 error accessing local IIS on Windows, access from other clients is fine

분류에서Dev

corrupted Arch Linux OS after accessing partition from Windows 7(dual boot)

분류에서Dev

accessing url parameter using jstl

분류에서Dev

Accessing nested hashes using variables

분류에서Dev

Accessing Docker Services from Host

분류에서Dev

Accessing MacOS X clipboard from

분류에서Dev

Accessing variable from JavaScript object

분류에서Dev

Accessing API from Chrome extension

분류에서Dev

Accessing AR from value object

분류에서Dev

Accessing timeline variables from a class?

분류에서Dev

Accessing a variable in a void from main

분류에서Dev

Accessing struct from double pointer

분류에서Dev

Accessing objects returned from a factory

분류에서Dev

Accessing value from nested hash

분류에서Dev

Different results for ls when accessing Ubuntu via SSH from different clients (Windows-PuTTy, Mac-Terminal)

분류에서Dev

Connect from Windows 10 to Ubuntu 15.04 using Windows Remote Desktop?

분류에서Dev

Customizing default tooltip without using any plugin

분류에서Dev

Get data for AJAX tooltip from URL adress

분류에서Dev

Accessing maven repo requiring windows creds with a mac

분류에서Dev

Accessing legacy BIOS following Windows 10 install

분류에서Dev

Accessing VPS linux hosting like RDP in Windows

분류에서Dev

Windows Linux Subsystem - Accessing Files outside of Ubuntu

분류에서Dev

Accessing the AWS S3 from on-premise world through Direct Connect, VPC and VPC Endpoint using AWS SDK

분류에서Dev

Can I downgrade to Windows 8 from Windows 8.1 using Windows 8 DVD?

Related 관련 기사

  1. 1

    Accessing partition created on Linux from Windows

  2. 2

    Accessing winreg from jython

  3. 3

    Accessing the user folder from a previous Windows installation (content on a read-only image)

  4. 4

    Accessing Ubuntu guest (VirtualBox) node.js server from Windows host

  5. 5

    Accessing children of second pivot item from code behind with their x:Name returns null in Windows Phone 8.1

  6. 6

    404 error accessing local IIS on Windows, access from other clients is fine

  7. 7

    corrupted Arch Linux OS after accessing partition from Windows 7(dual boot)

  8. 8

    accessing url parameter using jstl

  9. 9

    Accessing nested hashes using variables

  10. 10

    Accessing Docker Services from Host

  11. 11

    Accessing MacOS X clipboard from

  12. 12

    Accessing variable from JavaScript object

  13. 13

    Accessing API from Chrome extension

  14. 14

    Accessing AR from value object

  15. 15

    Accessing timeline variables from a class?

  16. 16

    Accessing a variable in a void from main

  17. 17

    Accessing struct from double pointer

  18. 18

    Accessing objects returned from a factory

  19. 19

    Accessing value from nested hash

  20. 20

    Different results for ls when accessing Ubuntu via SSH from different clients (Windows-PuTTy, Mac-Terminal)

  21. 21

    Connect from Windows 10 to Ubuntu 15.04 using Windows Remote Desktop?

  22. 22

    Customizing default tooltip without using any plugin

  23. 23

    Get data for AJAX tooltip from URL adress

  24. 24

    Accessing maven repo requiring windows creds with a mac

  25. 25

    Accessing legacy BIOS following Windows 10 install

  26. 26

    Accessing VPS linux hosting like RDP in Windows

  27. 27

    Windows Linux Subsystem - Accessing Files outside of Ubuntu

  28. 28

    Accessing the AWS S3 from on-premise world through Direct Connect, VPC and VPC Endpoint using AWS SDK

  29. 29

    Can I downgrade to Windows 8 from Windows 8.1 using Windows 8 DVD?

뜨겁다태그

보관