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