为什么我对winapi GetWindowPlacement的调用失败(使用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?
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"); } // ... }