Why is my JNA using the app not responding correctly?

I am trying to create a Java application using JNA to access window messages (e.g. WM_POINTERDOWN). With this option, I will turn my application into a touch application. So far, my current code gets this window, but maybe it overwrites some other important Java code, so the JFrame does not react as I expect (for example, when resizing the JFrame to a larger one, it fills the new black area added) .

This is my listener that will be called when a new window arrives:

public MyListener listener = new MyListener() {
        public LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam,
                LPARAM lParam) {

                    //handle the window message here

            return User32.INSTANCE.DefWindowProc(hWnd, uMsg, uParam, lParam);
        }
    };

MyListener Interface:

import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinDef.LPARAM;
import com.sun.jna.platform.win32.WinDef.LRESULT;
import com.sun.jna.platform.win32.WinDef.WPARAM;
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;

public interface MyListener extends StdCallCallback {

    public LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam);
}

In this snippet, I overwrite the native JFrame function that is usually called from the OS with my listener:

HWND hWnd = new HWND();
    hWnd.setPointer(Native.getWindowPointer(this));

    MyUser32.MYINSTANCE
            .SetWindowLong(hWnd, MyUser32.GWLP_WNDPROC, listener);

MyUser32 Class:

import com.sun.jna.Callback;
import com.sun.jna.Native;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.win32.W32APIOptions;

public interface MyUser32 extends User32 {

public static final MyUser32 MYINSTANCE = (MyUser32) Native.loadLibrary("user32", MyUser32.class, W32APIOptions.UNICODE_OPTIONS);

/**
 * Sets a new address for the window procedure (value to be set).
 */
public static final int GWLP_WNDPROC = -4;

/**
 * Changes an attribute of the specified window
 * @param   hWnd        A handle to the window
 * @param   nIndex      The zero-based offset to the value to be set.
 * @param   callback    The callback function for the value to be set.
 */
public int SetWindowLong(WinDef.HWND hWnd, int nIndex, Callback callback);

}

Maybe someone has a good idea about this. Thank.

+3
1

User32.INSTANCE.DefWindowProc, , SetWindowLong. :

(root) WndProc < - (A) (Swing) < - (B)

A, . Swing .

GetWindowLong/SetWindowLong (SetWindowLong ) CallWindowProc.

, GetWindowLongPtr/SetWindowLongPtr , ptr-postfixed, 32- 64- Windows. . SetWindowLong:

. SetWindowLongPtr . , 32-, 64- Windows, SetWindowLongPtr.

, - :

MyUser32:

    public interface MyUser32 extends User32 {

        public static final MyUser32 MYINSTANCE = (MyUser32) Native.loadLibrary("user32", MyUser32.class, W32APIOptions.UNICODE_OPTIONS);

        interface WNDPROC extends StdCallCallback {
            LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam, LPARAM lParam);
        }

        LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex) throws LastErrorException;

        LRESULT CallWindowProc(LONG_PTR proc, HWND hWnd, int uMsg, WPARAM uParam, WinDef.LPARAM lParam) throws LastErrorException;

        LONG_PTR SetWindowLongPtr(HWND hWnd, int nIndex, WNDPROC wndProc) throws LastErrorException;
    }

:

    private LONG_PTR baseWndProc;

    public MyUser32.WNDPROC listener = new MyUser32.WNDPROC () {
            public LRESULT callback(HWND hWnd, int uMsg, WPARAM uParam,
                    LPARAM lParam) {

                // TODO handle the window message

                // calling the base WndProc
                return MyUser32.MYINSTANCE.CallWindowProc(this.baseWndProc, hWnd, uMsg, wParam, lParam);
            }
        };

:

    this.baseWndProc = MyUser32.MYINSTANCE.SetWindowLongPtr(hWnd, MyUser32.GWL_WNDPROC, this.listener);

    this.baseWndProc = MyUser32.MYINSTANCE.GetWindowLongPtr(hWnd, MyUser32.GWL_WNDPROC);
    MyUser32.MYINSTANCE.SetWindowLongPtr(hWnd, MyUser32.GWL_WNDPROC, this.listener);
0

All Articles