2015-10-04 91 views
1

在解決如何在JNA中使用ClientToScreen winapi函數時遇到問題。JNA ClientToScreen?

我仍然得到0,0輸出的窗口句柄的座標。 AM引用此但是我相信我不是這樣做是正確https://msdn.microsoft.com/en-us/library/windows/desktop/dd183434(v=vs.85).aspx

public interface User32Ex extends W32APIOptions { 
    User32Ex instance = (User32Ex) Native.loadLibrary("user32", User32Ex.class, DEFAULT_OPTIONS); 
    boolean GetCursorPos(long[] lpPoint); 
    WinDef.HWND WindowFromPoint(long point); 
    boolean GetClientRect(WinDef.HWND hWnd, WinDef.RECT rect); 
    boolean ClientToScreen(WinDef.HWND hWnd, int pt); 
} 



public void debug() throws InterruptedException { 
    while (true) { 
     long[] getPos = new long[1]; 
     User32Ex.instance.GetCursorPos(getPos); 
     WinDef.HWND hwnd = User32Ex.instance.WindowFromPoint(getPos[0]); 

     WinDef.RECT rect = new WinDef.RECT(); 
     User32Ex.instance.GetClientRect(hwnd, rect); 
     User32Ex.instance.ClientToScreen(hwnd, rect.left); 
     User32Ex.instance.ClientToScreen(hwnd, rect.right); 

     System.out.println(rect.toRectangle().toString()); 
     Thread.sleep(1500); 
    } 
} 

回答

0

代替int,你需要在LPPOINT指針傳遞給ClientToScreen(),或者更具體的POINT結構(WinDef.POINT在JNA)。