Java Examples for com.sun.jna.platform.win32.WinDef.LRESULT
The following java examples will help you to understand the usage of com.sun.jna.platform.win32.WinDef.LRESULT. These source code samples are taken from different open source projects.
Example 1
| Project: btpka3.github.com-master File: Test04.java View source code |
public static void main(String[] args) {
HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null);
lpfn = new LowLevelKeyboardProc() {
int count = 1;
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT keyInfo) {
System.out.println("nCode =" + nCode + ", wParam =" + wParam + ", vkCode=" + keyInfo.vkCode);
count++;
if (count > 100) {
quit = true;
}
return User32.INSTANCE.CallNextHookEx(hHook, nCode, wParam, keyInfo.getPointer());
}
};
// 如果是全局钩子,则线程ID为0
int threadId = 0;
// int threadId =
// user32.GetWindowThreadProcessId(user32.FindWindow(null, "无标题 - 记事本"),
// null);
System.out.println("threadId = " + Integer.toHexString(threadId).toUpperCase());
int idHook = User32.WH_KEYBOARD_LL;
hHook = User32.INSTANCE.SetWindowsHookEx(idHook, lpfn, hMod, threadId);
if (hHook == null) {
System.out.println("键盘钩子安装失败,error = " + Kernel32.INSTANCE.GetLastError());
return;
}
User32.MSG msg = new User32.MSG();
while (!quit) {
User32.INSTANCE.PeekMessage(msg, null, 0, 0, 0);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (User32.INSTANCE.UnhookWindowsHookEx(hHook)) {
System.out.println("Unhooked");
}
}Example 2
| Project: topsun-master File: ScanBarcodeService.java View source code |
@Override
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
if (nCode >= 0) {
switch(wParam.intValue()) {
case WinUser.WM_KEYUP:
int keyCode = info.vkCode;
if (keyCode >= 48 && keyCode <= 57) {
listener.onKey(keyCode);
}
if (keyCode == 13) {
listener.onKey(keyCode);
}
break;
}
}
return lib.CallNextHookEx(hhkKeyBoard, nCode, wParam, info.getPointer());
}Example 3
| Project: jna-mirror-master File: KeyHook.java View source code |
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;
}
}
}
return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}Example 4
| Project: jna-master File: WindowUtils.java View source code |
@Override
public BufferedImage getWindowIcon(final HWND hwnd) {
// request different kind of icons if any solution fails
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);
if (result.intValue() == 0)
result = User32.INSTANCE.SendMessageTimeout(hwnd, WinUser.WM_GETICON, new WPARAM(WinUser.ICON_SMALL), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
if (result.intValue() == 0)
result = User32.INSTANCE.SendMessageTimeout(hwnd, WinUser.WM_GETICON, new WPARAM(WinUser.ICON_SMALL2), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber);
if (result.intValue() == 0) {
result = new LRESULT(User32.INSTANCE.GetClassLongPtr(hwnd, WinUser.GCLP_HICON).intValue());
hIconNumber.getValue().setValue(result.intValue());
}
if (result.intValue() == 0) {
result = new LRESULT(User32.INSTANCE.GetClassLongPtr(hwnd, WinUser.GCLP_HICONSM).intValue());
hIconNumber.getValue().setValue(result.intValue());
}
if (result.intValue() == 0)
return null;
// draw native icon into Java image
final HICON hIcon = new HICON(new Pointer(hIconNumber.getValue().longValue()));
final Dimension iconSize = getIconSize(hIcon);
if (iconSize.width == 0 || iconSize.height == 0)
return null;
final int width = iconSize.width;
final int height = iconSize.height;
final short depth = 24;
final byte[] lpBitsColor = new byte[width * height * depth / 8];
final Pointer lpBitsColorPtr = new Memory(lpBitsColor.length);
final byte[] lpBitsMask = new byte[width * height * depth / 8];
final Pointer lpBitsMaskPtr = new Memory(lpBitsMask.length);
final BITMAPINFO bitmapInfo = new BITMAPINFO();
final BITMAPINFOHEADER hdr = new BITMAPINFOHEADER();
bitmapInfo.bmiHeader = hdr;
hdr.biWidth = width;
hdr.biHeight = height;
hdr.biPlanes = 1;
hdr.biBitCount = depth;
hdr.biCompression = 0;
hdr.write();
bitmapInfo.write();
final HDC hDC = User32.INSTANCE.GetDC(null);
final ICONINFO iconInfo = new ICONINFO();
User32.INSTANCE.GetIconInfo(hIcon, iconInfo);
iconInfo.read();
GDI32.INSTANCE.GetDIBits(hDC, iconInfo.hbmColor, 0, height, lpBitsColorPtr, bitmapInfo, 0);
lpBitsColorPtr.read(0, lpBitsColor, 0, lpBitsColor.length);
GDI32.INSTANCE.GetDIBits(hDC, iconInfo.hbmMask, 0, height, lpBitsMaskPtr, bitmapInfo, 0);
lpBitsMaskPtr.read(0, lpBitsMask, 0, lpBitsMask.length);
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
int r, g, b, a, argb;
int x = 0, y = height - 1;
for (int i = 0; i < lpBitsColor.length; i = i + 3) {
b = lpBitsColor[i] & 0xFF;
g = lpBitsColor[i + 1] & 0xFF;
r = lpBitsColor[i + 2] & 0xFF;
a = 0xFF - lpBitsMask[i] & 0xFF;
argb = (a << 24) | (r << 16) | (g << 8) | b;
image.setRGB(x, y, argb);
x = (x + 1) % width;
if (x == 0)
y--;
}
User32.INSTANCE.ReleaseDC(null, hDC);
return image;
}Example 5
| Project: yajsw-maven-master File: WindowsXPMouse.java View source code |
public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) { LRESULT result = USER32INST.CallNextHookEx(hhk, nCode, wParam, info.getPointer()); if (nCode >= 0) { int action = wParam.intValue(); //System.out.println(action); switch(action) { case WM_LBUTTONDOWN: // do stuff break; case WM_RBUTTONDOWN: WindowsXPMouse.action.run(); break; case WM_MBUTTONDOWN: //do other stuff break; case WM_LBUTTONUP: WindowsXPMouse.action.run(); break; case WM_MOUSEMOVE: break; default: break; } /****************************DO NOT CHANGE, this code unhooks mouse *********************************/ if (threadFinish == true) { //System.out.println("post quit"); USER32INST.PostQuitMessage(0); } /***************************END OF UNCHANGABLE *******************************************************/ } return result; }
Example 6
| Project: spark-svn-mirror-master File: UserIdlePlugin.java View source code |
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:
// do active
userActive();
}
}
return lib.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
}Example 7
| Project: yajsw-maven-mk2-master File: WindowsXPMouse.java View source code |
public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) { LRESULT result = USER32INST.CallNextHookEx(hhk, nCode, wParam, info.getPointer()); if (nCode >= 0) { int action = wParam.intValue(); //System.out.println(action); switch(action) { case WM_LBUTTONDOWN: // do stuff break; case WM_RBUTTONDOWN: WindowsXPMouse.action.run(); break; case WM_MBUTTONDOWN: //do other stuff break; case WM_LBUTTONUP: WindowsXPMouse.action.run(); break; case WM_MOUSEMOVE: break; default: break; } /****************************DO NOT CHANGE, this code unhooks mouse *********************************/ if (threadFinish == true) { //System.out.println("post quit"); USER32INST.PostQuitMessage(0); } /***************************END OF UNCHANGABLE *******************************************************/ } return result; }