为什么我对winapi GetWindowPlacement的调用失败(使用JNA)?

时间:2015-07-09 09:00:33

标签: java winapi jna

这些是winapi方法

BOOL WINAPI SetWindowPlacement(
  _In_       HWND            hWnd,
  _In_ const WINDOWPLACEMENT *lpwndpl
);
typedef struct tagWINDOWPLACEMENT {
  UINT  length;
  UINT  flags;
  UINT  showCmd;
  POINT ptMinPosition;
  POINT ptMaxPosition;
  RECT  rcNormalPosition;
} WINDOWPLACEMENT, *PWINDOWPLACEMENT, *LPWINDOWPLACEMENT;

我的Java代码: -

class WINDOWPLACEMENT{
   public int length;
   public int flags;
   public int showCmd;
   public POINT    ptMinPosition;
   public POINT    ptMaxPosition;
   public RECT     rcNormalPosition;
}
WINDOWPLACEMENT wind = new WINDOWPLACEMENT();
User32Extra.INSTANCE.GetWindowPlacement(hwndLSM, wind);

错误是

  

java.lang.IllegalArgumentException:函数GetWindowPlacement的参数1处的不支持的参数类型jna.extra.WINDOWPLACEMENT

如何在JNA中使用GetWindowPlacement / SetWindowPlacement?

1 个答案:

答案 0 :(得分:1)

java.extra.WINDOWPLACEMENT必须延长com.sun.jna.Structure并正确实施getFieldOrder()

修改

在构造函数中设置长度,getFieldOrder()定义:

public class WINDOWPLACEMENT extends Structure {
    public WINDOWPLACEMENT() {
        this.length = size();
    }
    public List getFieldOrder() {
        return Arrays.asList("length", "flags", "showCmd", "ptMinPosition", "ptMaxPosition", "rcNormalPosition");
    }
    // ...
}