");
getProcessHandle.setRetVal(Type.INT);
nBufferGWT = new Pointer(MemoryBlockFactory.createMemoryBlock(4));
getProcessHandle.setParameter(0, hwnd.getValue());
getProcessHandle.setParameter(1, nBufferGWT);
getProcessHandle.invoke();
return nBufferGWT.getAsInt(0);
}
finally
{
try
{
if(nBufferGWT != null)
{
nBufferGWT.dispose();
}
nBufferGWT = null;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
public static HWND FindWindow(String className, String windowName) throws NativeException, IllegalAccessException
{
JNative _FindWindow = new JNative(DLL_NAME, "FindWindowA");
try
{
_FindWindow.setRetVal(Type.INT);
_FindWindow.setParameter(0, Type.STRING, className);
_FindWindow.setParameter(1, Type.STRING, windowName);
_Findwindows.invoke();
int valRet = Integer.parseInt(_FindWindow.getRetVal());
return new HWND(valRet);
}
finally
{
if(_FindWindow != null)
_FindWindow.dispose();
}
}
// Do _not_ use JNative's UINT for msg parameter. This makes windowprocs crash! Dont know why...
public static LRESULT CallWindowProc(LONG lpPrevWndFunc, HWND hwnd, int msg, WPARAM wparam,
LPARAM lparam)
throws NativeException, IllegalAccessException
{
JNative CallWindowProcA = new JNative(DLL_NAME, "CallWindowProcA");
CallWindowProcA.setRetVal(Type.INT);
int i = 0;
CallWindowProcA.setParameter(i++, lpPrevWndFunc.getValue());
CallWindowProcA.setParameter(i++, hwnd.getValue());
CallWindowProcA.setParameter(i++, msg);
CallWindowProcA.setParameter(i++, wparam.getValue());
CallWindowProcA.setParameter(i++, lparam.getValue());
CallWindowProcA.invoke();
return new LRESULT(CallWindowProcA.getRetValAsInt());
}
public static int CallWindowProc(int lpPrevWndFunc, int hwnd, int msg, int wparam,
int lparam)
throws NativeException, IllegalAccessException
{
JNative CallWindowProcA = new JNative(DLL_NAME, "CallWindowProcA");
CallWindowProcA.setRetVal(Type.INT);
int i = 0;
CallWindowProcA.setParameter(i++, lpPrevWndFunc);
CallWindowProcA.setParameter(i++, hwnd);
CallWindowProcA.setParameter(i++, msg);
CallWindowProcA.setParameter(i++, wparam);
CallWindowProcA.setParameter(i++, lparam);
CallWindowProcA.invoke();
return CallWindowProcA.getRetValAsInt();
}
public static LRESULT DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam,
LPARAM lparam) throws NativeException, IllegalAccessException
{
JNative DefWindowProc = new JNative(DLL_NAME, "DefWindowProcA");
DefWindowProc.setRetVal(Type.INT);
DefWindowProc.setParameter(0, Type.INT, hwnd.getValueAsString());
DefWindowProc.setParameter(1, Type.INT, msg.getValueAsString());
DefWindowProc.setParameter(2, Type.INT, wparam.getValueAsString());
DefWindowProc.setParameter(3, Type.INT, lparam.getValueAsString());
DefWindowProc.invoke();
return new LRESULT(DefWindowProc.getRetValAsInt());
}
public static int DefWindowProc(int hwnd, int msg, int wparam,
int lparam) throws NativeException, IllegalAccessException
{
JNative DefWindowProc = new JNative(DLL_NAME, "DefWindowProcA");
DefWindowProc.setRetVal(Type.INT);
DefWindowProc.setParameter(0, hwnd);
DefWindowProc.setParameter(1, msg);
DefWindowProc.setParameter(2, wparam);
DefWindowProc.setParameter(3, lparam);
DefWindowProc.invoke();
return DefWindowProc.getRetValAsInt();
}
public static boolean UpdateWindow(HWND hwnd) throws NativeException,
IllegalAccessException
{
JNative dm = new JNative(DLL_NAME, "UpdateWindow");
try
{
dm.setRetVal(Type.INT);
dm.setParameter(0, hwnd.getValue());
dm.invoke();
return (dm.getRetValAsInt() != 0);
}
finally
{
if(dm != null)
dm.dispose();
}
}
public static void DispatchMessage(MSG msg) throws NativeException,
IllegalAccessException
{
JNative dm = new JNative(DLL_NAME, "DispatchMessageA");
// dm.setRetVal(Type.INT);
dm.setParameter(0, msg.getValue().getPointer());
dm.invoke();
dm.dispose();
}
public static void TranslateMessage(MSG msg) throws NativeException,
IllegalAccessException
{
JNative dm = new JNative(DLL_NAME, "TranslateMessage");
// dm.setRetVal(Type.INT);
dm.setParameter(0, msg.getValue().getPointer());
dm.invoke();
dm.dispose();
}
public static int PeekMessage(MSG msg, HWND hwnd, int minMSG, int maxMSG, int removeMsg)
throws NativeException, IllegalAccessException
{
JNative gm = new JNative(DLL_NAME, "PeekMessageA");
gm.setRetVal(Type.INT);
gm.setParameter(0, msg.getValue().getPointer());
gm.setParameter(1, Type.INT, hwnd.getValueAsString());
gm.setParameter(2, Type.INT, "" + minMSG);
gm.setParameter(3, Type.INT, "" + maxMSG);
gm.setParameter(4, Type.INT, "" + removeMsg);
gm.invoke();
int ret = gm.getRetValAsInt();
gm.dispose();
return ret;
}
public static int GetMessage(MSG msg, HWND hwnd, int minMSG, int maxMSG)
throws NativeException, IllegalAccessException
{
JNative gm = new JNative(DLL_NAME, "GetMessageA");
gm.setRetVal(Type.INT);
gm.setParameter(0, msg.getValue().getPointer());
gm.setParameter(1, hwnd.getValue());
gm.setParameter(2, minMSG);
gm.setParameter(3, maxMSG);
gm.invoke();
int ret = gm.getRetValAsInt();
gm.dispose();
return ret;
}
public static boolean ShowWindow(HWND hwnd, int nCmdShow)
throws NativeException, IllegalAccessException
{
JNative w = new JNative(DLL_NAME, "ShowWindow");
w.setRetVal(Type.INT);
w.setParameter(0, hwnd.getValue());
w.setParameter(1, nCmdShow);
w.invoke();
return (w.getRetValAsInt() != 0);
}
public static final boolean DestroyWindow(HWND hWnd) throws NativeException, IllegalAccessException
{
if(hWnd == null)
{
return false;
}
JNative n = null;
try
{
n = new JNative(DLL_NAME, "DestroyWindow");
n.setRetVal(Type.INT);
n.setParameter(0, hWnd.getValue().intValue());
n.invoke();
return (n.getRetValAsInt() != 0);
}
finally
{
if (n != null)
{
n.dispose();
}
}
}
public static final int CreateWindowEx(int dwExStyle, String lpClassName,
String lpWindowName, int dwStyle, int x, int y, int nWidth,
int nHeight, int hWndParent, int hMenu, int hInstance, int lParam)
throws NativeException, IllegalAccessException
{
JNative n = null;
try
{
n = new JNative(DLL_NAME, "CreateWindowExA");
n.setRetVal(Type.INT);
int i = 0;
n.setParameter(i++, Type.INT, "" + dwExStyle);
n.setParameter(i++, Type.STRING, lpClassName);
if(lpWindowName == null)
{
n.setParameter(i++, 0);
}
else
{
n.setParameter(i++, Type.STRING, lpWindowName);
}
n.setParameter(i++, Type.INT, "" + dwStyle);
n.setParameter(i++, Type.INT, "" + x);
n.setParameter(i++, Type.INT, "" + y);
n.setParameter(i++, Type.INT, "" + nWidth);
n.setParameter(i++, Type.INT, "" + nHeight);
n.setParameter(i++, Type.INT, "" + hWndParent);
n.setParameter(i++, Type.INT, "" + hMenu);
n.setParameter(i++, Type.INT, ""
+ (hInstance == 0 ? JNative.getCurrentModule()
: hInstance));
n.setParameter(i++, Type.INT, "" + lParam);
n.invoke();
return Integer.parseInt(n.getRetVal());
}
finally
{
if (n != null)
{
n.dispose();
}
}
}
public static final int CreateWindowEx(int dwExStyle, LONG lpClassName,
String lpWindowName, int dwStyle, int x, int y, int nWidth,
int nHeight, int hWndParent, int hMenu, int hInstance, int lParam)
throws NativeException, IllegalAccessException
{
JNative n = null;
try
{
n = new JNative(DLL_NAME, "CreateWindowExA");
n.setRetVal(Type.INT);
int i = 0;
n.setParameter(i++, dwExStyle);
n.setParameter(i++, lpClassName.getValue());
if(lpWindowName == null)
{
n.setParameter(i++, 0);
}
else
{
n.setParameter(i++, lpWindowName);
}
n.setParameter(i++, dwStyle);
n.setParameter(i++, x);
n.setParameter(i++, y);
n.setParameter(i++, nWidth);
n.setParameter(i++, nHeight);
n.setParameter(i++, hWndParent);
n.setParameter(i++, hMenu);
n.setParameter(i++, (hInstance == 0 ? JNative.getCurrentModule() : hInstance));
n.setParameter(i++, lParam);
n.invoke();
return n.getRetValAsInt();
}
finally
{
if (n != null)
{
n.dispose();
}
}
}
public static final int MessageBox(int parentHandle, String message,
String caption, int buttons) throws NativeException, IllegalAccessException
{
JNative n = null;
try
{
n = new JNative(DLL_NAME, "MessageBoxA");
n.setRetVal(Type.INT);
int i = 0;
n.setParameter(i++, Type.INT, "" + parentHandle);
n.setParameter(i++, Type.STRING, message);
n.setParameter(i++, Type.STRING, caption);
n.setParameter(i++, Type.INT, "" + buttons);
n.invoke();
return Integer.parseInt(n.getRetVal());
}
finally
{
if (n != null)
n.dispose();
}
}
public static boolean EnumWindows(Callback lpEnumFunc, int lParam) throws NativeException, IllegalAccessException
{
JNative nEnumWindows = new JNative(DLL_NAME, "EnumWindows", false);
nEnumWindows.setRetVal(Type.INT);
nEnumWindows.setParameter(0, lpEnumFunc.getCallbackAddress());
nEnumWindows.setParameter(1, lParam);
nEnumWindows.invoke();
return !"0".equals(nEnumWindows.getRetVal());
}
public static String GetWindowText(HWND hwnd) throws NativeException, IllegalAccessException
{
JNative nGetWindowText = new JNative(DLL_NAME, "GetWindowTextA");
Pointer nBufferGWT = new Pointer(MemoryBlockFactory.createMemoryBlock(512));
try
{
nGetWindowText.setRetVal(Type.INT);
nGetWindowText.setParameter(0, hwnd.getValue());
nGetWindowText.setParameter(1, nBufferGWT);
nGetWindowText.setParameter(2, nBufferGWT.getSize());
nGetWindowText.invoke();
if ("0".equals(nGetWindowText.getRetVal()))
{
return "";
}
return nBufferGWT.getAsString();
}
finally
{
if(nBufferGWT != null)
{
nBufferGWT.dispose();
}
}
}
public static HANDLE LoadImage(LONG hinst,
String lpszName,
int uType,
int cxDesired,
int cyDesired,
int fuLoad) throws Exception
{
JNative LoadImage = new JNative(DLL_NAME, "LoadImageA");
LoadImage.setRetVal(Type.INT);
int i = 0;
LoadImage.setParameter(i++, hinst.getValue());
LoadImage.setParameter(i++, lpszName);
LoadImage.setParameter(i++, uType);
LoadImage.setParameter(i++, cxDesired);
LoadImage.setParameter(i++, cyDesired);
LoadImage.setParameter(i++, fuLoad);
LoadImage.invoke();
int ret = LoadImage.getRetValAsInt();
LoadImage.dispose();
return new HANDLE(ret);
}
public static LONG SetCursor(LONG hCursor) throws NativeException, IllegalAccessException
{
JNative SetCursor = new JNative(DLL_NAME, "SetCursor");
SetCursor.setRetVal(Type.INT);
SetCursor.setParameter(0, hCursor.getValue());
SetCursor.invoke();
int ret = SetCursor.getRetValAsInt();
SetCursor.dispose();
return new LONG(ret);
}
public static boolean SetSystemCursor(LONG hcur, DWORD id) throws NativeException, IllegalAccessException
{
JNative SetSystemCursor = new JNative(DLL_NAME, "SetSystemCursor");
SetSystemCursor.setRetVal(Type.INT);
SetSystemCursor.setParameter(0, hcur.getValue());
SetSystemCursor.setParameter(1, id.getValue());
SetSystemCursor.invoke();
int ret = SetSystemCursor.getRetValAsInt();
SetSystemCursor.dispose();
return (ret != 0);
}
public static DWORD GetClassLong(HWND hwnd, int nIndex) throws NativeException, IllegalAccessException
{
JNative GetClassLong = new JNative(DLL_NAME, "GetClassLongA");
GetClassLong.setRetVal(Type.INT);
GetClassLong.setParameter(0, hwnd.getValue());
GetClassLong.setParameter(1, nIndex);
GetClassLong.invoke();
int ret = GetClassLong.getRetValAsInt();
return new DWORD(ret);
}
public static DWORD SetClassLong(HWND hwnd, int nIndex, LONG dwNewLong) throws NativeException, IllegalAccessException
{
JNative SetClassLong = new JNative(DLL_NAME, "SetClassLongA");
SetClassLong.setRetVal(Type.INT);
int i = 0;
SetClassLong.setParameter(i++, hwnd.getValue());
SetClassLong.setParameter(i++, nIndex);
SetClassLong.setParameter(i++, dwNewLong.getValue());
SetClassLong.invoke();
return new DWORD(SetClassLong.getRetValAsInt());
}
public static LONG LoadCursorFromFile(String lpFileName) throws NativeException, IllegalAccessException
{
JNative LoadCursorFromFile = new JNative(DLL_NAME, "LoadCursorFromFileA");
LoadCursorFromFile.setRetVal(Type.INT);
LoadCursorFromFile.setParameter(0,lpFileName);
LoadCursorFromFile.invoke();
int ret = LoadCursorFromFile.getRetValAsInt();
LoadCursorFromFile.dispose();
return new LONG(ret);
}
public static int SetWindowLong(HWND hwnd, int nIndex, LONG dwNewLong) throws NativeException, IllegalAccessException
{
if(hwnd == null)
{
return 0;
}
JNative _setWindowLong = new JNative(DLL_NAME, "SetWindowLongA");
_setWindowLong.setRetVal(Type.INT);
_setWindowLong.setParameter(0, hwnd.getValue());
_setWindowLong.setParameter(1, nIndex);
_setWindowLong.setParameter(2, dwNewLong.getValue());
_setWindowLong.invoke();
int ret = _setWindowLong.getRetValAsInt();
_setWindowLong.dispose();
return ret;
}
public static boolean UnhookWindowsHookEx(int hHook) throws NativeException, IllegalAccessException
{
JNative UnhookWindowsHookEx = new JNative(DLL_NAME, "UnhookWindowsHookEx");
UnhookWindowsHookEx.setRetVal(Type.INT);
UnhookWindowsHookEx.setParameter(0, hHook);
UnhookWindowsHookEx.invoke();
int ret = UnhookWindowsHookEx.getRetValAsInt();
UnhookWindowsHookEx.dispose();
return (ret != 0);
}
public static int SetWindowsHookEx(int idHook, int lpfn, int hMod, DWORD dwThreadId) throws NativeException, IllegalAccessException
{
JNative SetWindowsHookEx = new JNative(DLL_NAME, "SetWindowsHookExA");
SetWindowsHookEx.setRetVal(Type.INT);
int pos = 0;
SetWindowsHookEx.setParameter(pos++, idHook);
SetWindowsHookEx.setParameter(pos++, lpfn);
SetWindowsHookEx.setParameter(pos++, hMod);
SetWindowsHookEx.setParameter(pos++, dwThreadId.getValue());
SetWindowsHookEx.invoke();
pos = SetWindowsHookEx.getRetValAsInt();
SetWindowsHookEx.dispose();
return pos;
}
public static int CallNextHookEx(int hhk, int nCode, int wParam, int lParam) throws NativeException, IllegalAccessException
{
JNative CallNextHookEx = new JNative(DLL_NAME, "CallNextHookEx");
CallNextHookEx.setRetVal(Type.INT);
int pos = 0;
CallNextHookEx.setParameter(pos++, hhk);
CallNextHookEx.setParameter(pos++, nCode);
CallNextHookEx.setParameter(pos++, wParam);
CallNextHookEx.setParameter(pos++, lParam);
CallNextHookEx.invoke();
pos = CallNextHookEx.getRetValAsInt();
CallNextHookEx.dispose();
return pos;
}
public static LONG RegisterClass(WNDCLASS lpWndClass) throws NativeException, IllegalAccessException
{
JNative registerClass = new JNative(DLL_NAME, "RegisterClassA");
registerClass.setRetVal(Type.INT);
registerClass.setParameter(0, lpWndClass.createPointer());
registerClass.invoke();
int i = registerClass.getRetValAsInt();
registerClass.dispose();
return new LONG(i);
}
public static LONG RegisterClassEx(WNDCLASSEX lpWndClass) throws NativeException, IllegalAccessException
{
JNative RegisterClassEx = new JNative(DLL_NAME, "RegisterClassExA");
RegisterClassEx.setRetVal(Type.INT);
RegisterClassEx.setParameter(0, lpWndClass.createPointer());
RegisterClassEx.invoke();
int i = RegisterClassEx.getRetValAsInt();
RegisterClassEx.dispose();
return new LONG(i);
}
public static int GetClassName(HWND hWnd, Pointer lpClassName, int nMaxCount) throws NativeException, IllegalAccessException
{
JNative GetClassName = new JNative(DLL_NAME, "GetClassNameA");
GetClassName.setRetVal(Type.INT);
int i = 0;
GetClassName.setParameter(i++, hWnd.getValue());
GetClassName.setParameter(i++, lpClassName);
GetClassName.setParameter(i++, nMaxCount);
GetClassName.invoke();
i = GetClassName.getRetValAsInt();
GetClassName.dispose();
return i;
}
public static boolean GetClassInfo(int hInstance, String lpClassName, WNDCLASS lpWndClass) throws NativeException, IllegalAccessException
{
JNative GetClassInfo = new JNative(DLL_NAME, "GetClassInfoA");
GetClassInfo.setRetVal(Type.INT);
int i = 0;
GetClassInfo.setParameter(i++, hInstance);
GetClassInfo.setParameter(i++, lpClassName);
GetClassInfo.setParameter(i++, lpWndClass.createPointer());
GetClassInfo.invoke();
i = GetClassInfo.getRetValAsInt();
GetClassInfo.dispose();
return (i != 0);
}
public static boolean GetClassInfoEx(int hInstance, String lpClassName, WNDCLASSEX lpWndClass) throws NativeException, IllegalAccessException
{
JNative GetClassInfo = new JNative(DLL_NAME, "GetClassInfoExA");
GetClassInfo.setRetVal(Type.INT);
int i = 0;
GetClassInfo.setParameter(i++, hInstance);
GetClassInfo.setParameter(i++, lpClassName);
GetClassInfo.setParameter(i++, lpWndClass.createPointer());
GetClassInfo.invoke();
i = GetClassInfo.getRetValAsInt();
GetClassInfo.dispose();
return (i != 0);
}
public static LONG LoadIcon(LONG hInstance, String lpIconName) throws NativeException, IllegalAccessException
{
JNative loadIcon = new JNative(DLL_NAME, "LoadIconA");
loadIcon.setRetVal(Type.INT);
loadIcon.setParameter(0, hInstance.getValue());
loadIcon.setParameter(1, lpIconName);
loadIcon.invoke();
int ret = loadIcon.getRetValAsInt();
loadIcon.dispose();
return new LONG(ret);
}
public static LONG LoadIcon(LONG hInstance, int ressource) throws NativeException, IllegalAccessException
{
JNative loadIcon = new JNative(DLL_NAME, "LoadIconA");
loadIcon.setRetVal(Type.INT);
loadIcon.setParameter(0, hInstance.getValue());
loadIcon.setParameter(1, ressource);
loadIcon.invoke();
int ret = loadIcon.getRetValAsInt();
loadIcon.dispose();
return new LONG(ret);
}
public static LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) throws NativeException, IllegalAccessException
{
JNative SendMessage = new JNative(DLL_NAME, "SendMessageA");
SendMessage.setRetVal(Type.INT);
int pos = 0;
SendMessage.setParameter(pos++, hWnd.getValue());
SendMessage.setParameter(pos++, Msg.getValue());
SendMessage.setParameter(pos++, wParam.getValue());
SendMessage.setParameter(pos++, lParam.getValue());
SendMessage.invoke();
pos = SendMessage.getRetValAsInt();
SendMessage.dispose();
return new LRESULT(pos);
}
public static boolean PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) throws NativeException, IllegalAccessException
{
JNative SendMessage = new JNative(DLL_NAME, "PostMessageA");
SendMessage.setRetVal(Type.INT);
int pos = 0;
SendMessage.setParameter(pos++, hWnd.getValue());
SendMessage.setParameter(pos++, Msg.getValue());
SendMessage.setParameter(pos++, wParam.getValue());
SendMessage.setParameter(pos++, lParam.getValue());
SendMessage.invoke();
pos = SendMessage.getRetValAsInt();
SendMessage.dispose();
return (pos != 0);
}
public static LONG CreateIcon(LONG hInstance, int nWidth, int nHeight, int cPlanes,
int cBitsPixel, int[] lpbANDbits, int[] lpbXORbits)
throws NativeException, IllegalAccessException
{
JNative createIcon = new JNative(DLL_NAME, "CreateIcon");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(lpbXORbits.length*4));
for(int i = 0; i
{
p.setIntAt(i*4,lpbXORbits[i]);
}
createIcon.setRetVal(Type.INT);
int i = 0;
createIcon.setParameter(i++, hInstance.getValue());
createIcon.setParameter(i++, nWidth);
createIcon.setParameter(i++, nHeight);
createIcon.setParameter(i++, cPlanes);
createIcon.setParameter(i++, cBitsPixel);
createIcon.setParameter(i++, p);
createIcon.setParameter(i++, p);
createIcon.invoke();
i = createIcon.getRetValAsInt();
createIcon.dispose();
return new LONG(i);
}
public static LONG GetWindowLong(HWND hWnd,
int nIndex) throws NativeException, IllegalAccessException
{
JNative GetWindowLong = new JNative(DLL_NAME, "GetWindowLongA");
GetWindowLong.setRetVal(Type.INT);
int pos = 0;
GetWindowLong.setParameter(pos++, hWnd.getValue());
GetWindowLong.setParameter(pos++, nIndex);
GetWindowLong.invoke();
pos = GetWindowLong.getRetValAsInt();
GetWindowLong.dispose();
return new LONG(pos);
}
public static boolean AttachThreadInput(int idAttach,
int idAttachTo,
boolean fAttach)
throws NativeException, IllegalAccessException
{
JNative AttachThreadInput = new JNative(DLL_NAME, "AttachThreadInput");
AttachThreadInput.setRetVal(Type.INT);
int pos = 0;
AttachThreadInput.setParameter(pos++, idAttach);
AttachThreadInput.setParameter(pos++, idAttachTo);
AttachThreadInput.setParameter(pos++, fAttach ? "1" : "0");
AttachThreadInput.invoke();
pos = AttachThreadInput.getRetValAsInt();
AttachThreadInput.dispose();
if(pos == 0)
return false;
return true;
}
public static HWND GetForegroundWindow() throws NativeException, IllegalAccessException
{
JNative GetForegroundWindow = new JNative(DLL_NAME, "GetForegroundWindow");
GetForegroundWindow.setRetVal(Type.INT);
GetForegroundwindows.invoke();
int ret = GetForegroundWindow.getRetValAsInt();
GetForegroundWindow.dispose();
return new HWND(ret);
}
public static HWND GetActiveWindow() throws NativeException, IllegalAccessException
{
JNative GetActiveWindow = new JNative(DLL_NAME, "GetActiveWindow");
GetActiveWindow.setRetVal(Type.INT);
GetActivewindows.invoke();
int ret = GetActiveWindow.getRetValAsInt();
GetActiveWindow.dispose();
return new HWND(ret);
}
public static HWND SetActiveWindow(HWND hWnd) throws NativeException, IllegalAccessException
{
JNative SetActiveWindow = new JNative(DLL_NAME, "SetActiveWindow");
SetActiveWindow.setRetVal(Type.INT);
int pos = 0;
SetActiveWindow.setParameter(pos++, hWnd.getValue());
SetActivewindows.invoke();
pos = SetActiveWindow.getRetValAsInt();
SetActiveWindow.dispose();
return new HWND(pos);
}
public static boolean SetForegroundWindow(HWND hWnd) throws NativeException, IllegalAccessException
{
JNative SetForegroundWindow = new JNative(DLL_NAME, "SetForegroundWindow");
SetForegroundWindow.setRetVal(Type.INT);
int pos = 0;
SetForegroundWindow.setParameter(pos++, hWnd.getValue());
SetForegroundwindows.invoke();
pos = SetForegroundWindow.getRetValAsInt();
SetForegroundWindow.dispose();
if(pos == 0)
return false;
return true;
}
public static boolean DestroyIcon(LONG hIcon) throws NativeException, IllegalAccessException
{
JNative DestroyIcon = new JNative(DLL_NAME, "DestroyIcon");
DestroyIcon.setRetVal(Type.INT);
int pos = 0;
DestroyIcon.setParameter(0, hIcon.getValue());
DestroyIcon.invoke();
pos = DestroyIcon.getRetValAsInt();
DestroyIcon.dispose();
return (pos != 0);
}
public static int RegisterWindowMessage(String lpString) throws NativeException, IllegalAccessException
{
JNative RegisterWindowMessage = new JNative(DLL_NAME, "RegisterWindowMessageA");
RegisterWindowMessage.setRetVal(Type.INT);
int pos = 0;
RegisterWindowMessage.setParameter(pos++, lpString);
RegisterWindowMessage.invoke();
pos = RegisterWindowMessage.getRetValAsInt();
RegisterWindowMessage.dispose();
return pos;
}
public static boolean SetWindowPos(HWND hWnd,
HWND hWndInsertAfter,
int X,
int Y,
int cx,
int cy,
int uFlags)
throws NativeException, IllegalAccessException
{
JNative SetWindowPos = new JNative(DLL_NAME, "SetWindowPos");
SetWindowPos.setRetVal(Type.INT);
int pos = 0;
SetWindowPos.setParameter(pos++, hWnd.getValue());
SetWindowPos.setParameter(pos++, hWndInsertAfter.getValue());
SetWindowPos.setParameter(pos++, X);
SetWindowPos.setParameter(pos++, Y);
SetWindowPos.setParameter(pos++, cx);
SetWindowPos.setParameter(pos++, cy);
SetWindowPos.setParameter(pos++, uFlags);
SetWindowPos.invoke();
pos = SetWindowPos.getRetValAsInt();
SetWindowPos.dispose();
if(pos == 0)
return false;
return true;
}
public static boolean RegisterHotKey(HWND hWnd,
int id,
int fsModifiers,
int vk)
throws NativeException, IllegalAccessException
{
JNative RegisterHotKey = new JNative(DLL_NAME, "RegisterHotKey");
RegisterHotKey.setRetVal(Type.INT);
int pos = 0;
RegisterHotKey.setParameter(pos++, hWnd.getValue());
RegisterHotKey.setParameter(pos++, id);
RegisterHotKey.setParameter(pos++, fsModifiers);
RegisterHotKey.setParameter(pos++, vk);
RegisterHotKey.invoke();
pos = RegisterHotKey.getRetValAsInt();
RegisterHotKey.dispose();
return (pos != 0);
}
public static boolean UnregisterHotKey(HWND hWnd, int id) throws NativeException, IllegalAccessException
{
JNative UnregisterHotKey = new JNative(DLL_NAME, "UnregisterHotKey");
UnregisterHotKey.setRetVal(Type.INT);
int pos = 0;
UnregisterHotKey.setParameter(pos++, hWnd.getValue());
UnregisterHotKey.setParameter(pos++, id);
UnregisterHotKey.invoke();
pos = UnregisterHotKey.getRetValAsInt();
UnregisterHotKey.dispose();
return (pos != 0);
}
public static boolean GetWindowRect(HWND hwnd, LRECT rect) throws NativeException, IllegalAccessException
{
JNative GetWindowRect = new JNative(DLL_NAME, "GetWindowRect");
GetWindowRect.setRetVal(Type.INT);
int pos = 0;
GetWindowRect.setParameter(pos++, hwnd.getValue());
GetWindowRect.setParameter(pos++, rect.getPointer());
GetWindowRect.invoke();
pos = GetWindowRect.getRetValAsInt();
GetWindowRect.dispose();
return (pos != 0);
}
public static final int DEVICE_NOTIFY_WINDOW_HANDLE = 0;
public static final int DEVICE_NOTIFY_SERVICE_HANDLE = 1;
public static final int DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 4;
public static HANDLE RegisterDeviceNotification(HANDLE hRecipient, int Flags) throws NativeException, IllegalAccessException
{
JNative registerDeviceNotification = new JNative(DLL_NAME, "RegisterDeviceNotificationA");
registerDeviceNotification.setRetVal(Type.INT);
int pos = 0;
DEV_BROADCAST_HANDLE dbh = new DEV_BROADCAST_HANDLE(DEV_BROADCAST_HANDLE.DBT_DEVTYP_DEVICEINTERFACE, GUID.GUID_IO_MEDIA_ARRIVAL);
registerDeviceNotification.setParameter(pos++, hRecipient.getValue());
registerDeviceNotification.setParameter(pos++, dbh.getPointer());
registerDeviceNotification.setParameter(pos++, Flags);
registerDeviceNotification.invoke();
final int retValAsInt = registerDeviceNotification.getRetValAsInt();
if(retValAsInt == 0)
{
JNative.getLogger().log("GetLastError "+Kernel32.GetLastError());
}
JNative.getLogger().log("return value : " + retValAsInt);
return dbh.getDbch_hdevnotify();
}
public static int CreateCursor(HANDLE hInst,
int xHotSpot,
int yHotSpot,
int nWidth,
int nHeight,
Pointer pvANDPlane,
Pointer pvXORPlane) throws NativeException, IllegalAccessException
{
JNative CreateCursor = new JNative(DLL_NAME, "CreateCursor");
CreateCursor.setRetVal(Type.INT);
int pos = 0;
CreateCursor.setParameter(pos++, hInst.getValue());
CreateCursor.setParameter(pos++, xHotSpot);
CreateCursor.setParameter(pos++, yHotSpot);
CreateCursor.setParameter(pos++, nWidth);
CreateCursor.setParameter(pos++, nHeight);
CreateCursor.setParameter(pos++, pvANDPlane.getPointer());
CreateCursor.setParameter(pos++, pvXORPlane.getPointer());
CreateCursor.invoke();
return CreateCursor.getRetValAsInt();
}
public static boolean DestroyCursor(int hCursor) throws NativeException, IllegalAccessException
{
JNative DestroyCursor = new JNative(DLL_NAME, "DestroyCursor");
DestroyCursor.setRetVal(Type.INT);
int pos = 0;
DestroyCursor.setParameter(pos++, hCursor);
DestroyCursor.invoke();
pos = DestroyCursor.getRetValAsInt();
return (pos != 0);
}
public static HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter,
String className, String windowName) throws NativeException,
IllegalAccessException
{
JNative FindWindowEx = new JNative(DLL_NAME, "FindWindowExA");
FindWindowEx.setRetVal(Type.INT);
FindWindowEx.setParameter(0, hwndParent.getValue());
FindWindowEx.setParameter(1, hwndChildAfter.getValue());
FindWindowEx.setParameter(2, className);
FindWindowEx.setParameter(3, windowName);
FindWindowEx.invoke();
return new HWND(FindWindowEx.getRetValAsInt());
}
public static boolean EnumChildWindows(HWND hWndParent,
Callback lpEnumFunc, int lParam) throws NativeException,
IllegalAccessException
{
JNative nEnumWindows = new JNative(DLL_NAME, "EnumChildWindows", false);
nEnumWindows.setRetVal(Type.INT);
nEnumWindows.setParameter(0, hWndParent.getValue());
nEnumWindows.setParameter(1, lpEnumFunc.getCallbackAddress());
nEnumWindows.setParameter(2, lParam);
nEnumWindows.invoke();
return !"0".equals(nEnumWindows.getRetVal());
}
}