有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Createwindowex无效句柄错误

我正在使用jna函数调用winapi

public muFunction(){
  Magnification.INSTANCE.MagInitialize();
  RECT desktopRect= new RECT();
  HWND desktop = User32.INSTANCE.GetDesktopWindow();
  User32Extra.INSTANCE.GetWindowRect(desktop, desktopRect);
  HINSTANCE hInstance =Kernel32.INSTANCE.GetModuleHandle(null);

  HWND lsm = User32Extra.INSTANCE.FindWindow(null, "MyWindow");
  HWND hwndMag = User32Extra.INSTANCE.CreateWindowEx(new DWORD(0x00000000L), "Magnifier", "MagnifierWindow", new DWORD(0x40000000L|0x0001L|0x10000000L), desktopRect.left, desktopRect.top, desktopRect.right-desktopRect.left, desktopRect.bottom-desktopRect.top, desktop, null, hInstance, null);
  System.out.println(Native.getLastError()); // return 6 as error
}

放大Api代码

public interface Magnification extends StdCallLibrary {

    Magnification INSTANCE = (Magnification) Native.loadLibrary("magnification", Magnification.class,
                                                W32APIOptions.DEFAULT_OPTIONS);

    public Boolean MagInitialize();

    public boolean MagSetWindowFilterList(HWND hwndMag, DWORD dword, int i,
            HWND[] excludeHWNDs);

    public boolean MagSetWindowSource(HWND hwndMag, RECT sourceRect);

}

我得到了ERROR_INVALID_HANDLE错误。我的代码有什么问题

谢谢


共 (1) 个答案

  1. # 1 楼答案

    你的代码有很多问题。您不执行错误检查,正如在注释中详细介绍的那样。你真的需要解决这个问题

    您还可以对窗口样式使用魔法常量。请声明命名常量,以便将来的读者(即您)能够理解代码。关键的一点是你对WS_CHILD的使用。无法使桌面窗口成为子窗口的父窗口。您需要提供另一个窗口作为父窗口