本文介绍了为什么我对winapi GetWindowPlacement的调用失败(使用JNA)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些是winapi方法

These are the winapi methods

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代码: -

My Java code:-

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

错误是

如何使用GetWindowPlacement / SetWindowPlacement with JNA?

How to use GetWindowPlacement/SetWindowPlacement with JNA?

推荐答案

java.extra.WINDOWPLACEMENT 必须extend com.sun.jna.Structure 并正确实现 getFieldOrder()

java.extra.WINDOWPLACEMENT must extend com.sun.jna.Structure and properly implement getFieldOrder().

编辑

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

Setting length in the constructor, and getFieldOrder() definition:

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

这篇关于为什么我对winapi GetWindowPlacement的调用失败(使用JNA)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:14