-2

I am using jna functions to call 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
}

Magnification Api code

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

}

I am getting ERROR_INVALID_HANDLE error. What is wrong with my code.

Thanks

4

1 回答 1

2

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

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

于 2015-07-27T13:10:48.643 回答