use of com.sun.jna.platform.win32.WinDef.LPARAM in project jna by java-native-access.
the class Kernel32Test method testEnumResourceNames.
public void testEnumResourceNames() {
// "14" is the type name of the My Computer icon in explorer.exe
Pointer pointer = new Memory(Native.WCHAR_SIZE * 3);
pointer.setWideString(0, "14");
WinBase.EnumResNameProc ernp = new WinBase.EnumResNameProc() {
@Override
public boolean invoke(HMODULE module, Pointer type, Pointer name, Pointer lParam) {
return true;
}
};
// null HMODULE means use this process / its EXE
// there are no type "14" resources in it.
boolean result = Kernel32.INSTANCE.EnumResourceNames(null, pointer, ernp, null);
assertFalse("EnumResourceNames should have failed.", result);
assertEquals("GetLastError should be set to 1813", WinError.ERROR_RESOURCE_TYPE_NOT_FOUND, Kernel32.INSTANCE.GetLastError());
}
use of com.sun.jna.platform.win32.WinDef.LPARAM in project jna by java-native-access.
the class WindowUtilsTest method testGetIconSize.
public void testGetIconSize() throws Exception {
final JFrame w = new JFrame();
try {
final BufferedImage expectedIcon = ImageIO.read(new FileInputStream(new File(getClass().getResource("/res/test_icon.png").getPath())));
w.setIconImage(expectedIcon);
w.setVisible(true);
Pointer p = Native.getComponentPointer(w);
assertNotNull("Could not obtain native HANDLE for JFrame", p);
HWND hwnd = new HWND(p);
final DWORDByReference hIconNumber = new DWORDByReference();
LRESULT result = User32.INSTANCE.SendMessageTimeout(hwnd, WinUser.WM_GETICON, new WPARAM(WinUser.ICON_BIG), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
assertNotEquals(0, result.intValue());
final HICON hIcon = new HICON(new Pointer(hIconNumber.getValue().longValue()));
assertTrue(WindowUtils.getIconSize(hIcon).width >= 32);
assertTrue(WindowUtils.getIconSize(hIcon).height >= 32);
assertEquals(WindowUtils.getIconSize(hIcon).width, WindowUtils.getIconSize(hIcon).height);
} finally {
w.dispose();
}
}
use of com.sun.jna.platform.win32.WinDef.LPARAM in project jna by java-native-access.
the class KeyHook method main.
public static void main(String[] args) {
final User32 lib = User32.INSTANCE;
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
keyboardHook = new LowLevelKeyboardProc() {
@Override
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
if (nCode >= 0) {
switch(wParam.intValue()) {
case WinUser.WM_KEYUP:
case WinUser.WM_KEYDOWN:
case WinUser.WM_SYSKEYUP:
case WinUser.WM_SYSKEYDOWN:
System.err.println("in callback, key=" + info.vkCode);
if (info.vkCode == 81) {
quit = true;
}
}
}
Pointer ptr = info.getPointer();
long peer = Pointer.nativeValue(ptr);
return lib.CallNextHookEx(hhk, nCode, wParam, new LPARAM(peer));
}
};
hhk = lib.SetWindowsHookEx(WinUser.WH_KEYBOARD_LL, keyboardHook, hMod, 0);
System.out.println("Keyboard hook installed, type anywhere, 'q' to quit");
new Thread() {
@Override
public void run() {
while (!quit) {
try {
Thread.sleep(10);
} catch (Exception e) {
}
}
System.err.println("unhook and exit");
lib.UnhookWindowsHookEx(hhk);
System.exit(0);
}
}.start();
// This bit never returns from GetMessage
int result;
MSG msg = new MSG();
while ((result = lib.GetMessage(msg, null, 0, 0)) != 0) {
if (result == -1) {
System.err.println("error in get message");
break;
} else {
System.err.println("got message");
lib.TranslateMessage(msg);
lib.DispatchMessage(msg);
}
}
lib.UnhookWindowsHookEx(hhk);
}
use of com.sun.jna.platform.win32.WinDef.LPARAM in project jna by java-native-access.
the class MonitorInfoDemo method main.
/**
* @param args (ignored)
*/
public static void main(String[] args) {
System.out.println("Installed Physical Monitors: " + User32.INSTANCE.GetSystemMetrics(WinUser.SM_CMONITORS));
User32.INSTANCE.EnumDisplayMonitors(null, null, new MONITORENUMPROC() {
@Override
public int apply(HMONITOR hMonitor, HDC hdc, RECT rect, LPARAM lparam) {
enumerate(hMonitor);
return 1;
}
}, new LPARAM(0));
}
Aggregations