I'm trying to build a java application by using the JNA to gain access to the window messages (for e.g WM_POINTERDOWN). With this option, I will turn my application into a touch-sensitive application. So far my current code gets this window messages but possibly overwrites some other important java native code so that the JFrame doesn't react in the way I expect (for example, while resizing the JFrame to a bigger one, it fills the new added area black).
This is my Listener, which will be called when a new window message 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);
}
};
The Interface MyListener:
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 function of the JFrame, which will be normally called from the OS, with my listener:
HWND hWnd = new HWND();
hWnd.setPointer(Native.getWindowPointer(this));
MyUser32.MYINSTANCE
.SetWindowLong(hWnd, MyUser32.GWLP_WNDPROC, listener);
The class MyUser32:
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. Thanks.