@Override public synchronized void unhook() { LOG.info("Interrupting mouse events hook thread"); User32.INSTANCE.PostThreadMessage(mouseHookThreadID, WinUser.WM_QUIT, new WinDef.WPARAM(), new WinDef.LPARAM()); awaitUtils.waitFor(() -> mouseHookThreadID == 0, 2000L, () -> LOG.error("Failed to unhook mouse events in time")); }
@Override public void run(final HWND hWnd, final WPARAM wParam, final LPARAM lParam) { int lp = lParam.intValue(); switch (lp) { case WM_LBUTTONUP: case WM_RBUTTONUP: if (popupMenu != null && User32.User32.GetCursorPos(mousePosition)) { Point point = new Point(mousePosition.x, mousePosition.y); popupMenu.doShow(point, 0); } break; default: break; } } };
private String readFileNameFromInput(LPARAM lParam) { Class structPlatformClass = (Platform.is64Bit()) ? PuttyStruct64.class : PuttyStruct32.class; PuttyStruct ps = (PuttyStruct) PuttyStruct.newInstance(structPlatformClass, new Pointer(lParam.longValue())); ps.read(); return new String(ps.lpData.getString(0).getBytes(Charset.forName("US-ASCII"))); }
WinUser.WM_GETICON, new WPARAM(WinUser.ICON_BIG), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber); if (result.intValue() == 0) WinUser.WM_GETICON, new WPARAM(WinUser.ICON_SMALL), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber); if (result.intValue() == 0) WinUser.WM_GETICON, new WPARAM(WinUser.ICON_SMALL2), new LPARAM(0), WinUser.SMTO_ABORTIFHUNG, 500, hIconNumber); if (result.intValue() == 0) {
public LRESULT callback(HWND hWnd, int msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_SHELLNOTIFY: switch (lParam.intValue()) { case WM_LBUTTONUP: for (Listener l : Collections.synchronizedCollection(listeners)) { MEASUREITEMSTRUCT ms = new MEASUREITEMSTRUCT(new Pointer(lParam.longValue())); MenuMap mm = hMenusIDs.get(ms.itemData.intValue()); SIZE size = measureItem(hWnd, mm); DRAWITEMSTRUCT di = new DRAWITEMSTRUCT(new Pointer(lParam.longValue())); MenuMap mm = hMenusIDs.get(di.itemData.intValue());
@Override public WinDef.LRESULT callback(int nCode, WinDef.WPARAM wParam, MSLLHOOKSTRUCT info) { if (nCode >= 0) { switch (wParam.intValue()) { case JNIMouseHook.WM_LBUTTONDOWN: addEventToQueue(info.pt.x, info.pt.y); break; case JNIMouseHook.WM_RBUTTONDOWN: addEventToQueue(info.pt.x, info.pt.y); break; case JNIMouseHook.WM_MBUTTONDOWN: addEventToQueue(info.pt.x, info.pt.y); break; case JNIMouseHook.WM_MOUSEMOVE: break; default: break; } // unhook if needed if (threadFinish == true) { USER32INST.PostQuitMessage(0); } } Pointer ptr = info.getPointer(); long peer = Pointer.nativeValue(ptr); return USER32INST.CallNextHookEx(hhk, nCode, wParam, new LPARAM(peer)); } };
/** * Get the current state of a window. * * @param hWnd native window handle * @return window state */ private WindowState getWindowState(HWND hWnd) { WindowState windowState = new WindowState(); windowState.setMaximized(ExtendedUser32.INSTANCE.IsZoomed(hWnd)); if (windowState.getMaximized()) { ExtendedUser32.INSTANCE.SendMessage(hWnd, User32.WM_SYSCOMMAND, new WPARAM(ExtendedUser32.SC_RESTORE), new LPARAM(0)); } windowState.setStyle(ExtendedUser32.INSTANCE.GetWindowLong(hWnd, ExtendedUser32.GWL_STYLE)); windowState.setExStyle(ExtendedUser32.INSTANCE.GetWindowLong(hWnd, ExtendedUser32.GWL_EXSTYLE)); RECT rect = new RECT(); boolean gotWindowRect = ExtendedUser32.INSTANCE.GetWindowRect(hWnd, rect); if (gotWindowRect) { windowState.setLeft(rect.left); windowState.setTop(rect.top); windowState.setRight(rect.right); windowState.setBottom(rect.bottom); } return windowState; }
/** * Set the full-screen state of the window. * * @param fullScreen <code>true</code> to set full-screen; <code>false</code> to exit full-screen */ void setFullScreen(boolean fullScreen) { HWND hWnd = getHWND(Native.getComponentID(window)); if (fullScreen) { windowState = getWindowState(hWnd); ExtendedUser32.INSTANCE.SetWindowLong(hWnd, GWL_STYLE, windowState.getStyle() & ~(WS_CAPTION | WS_THICKFRAME)); ExtendedUser32.INSTANCE.SetWindowLong(hWnd, GWL_EXSTYLE, windowState.getExStyle() & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); MONITORINFO monitorInfo = getMonitorInfo(hWnd); RECT rect = monitorInfo.rcMonitor; ExtendedUser32.INSTANCE.SetWindowPos(hWnd, null, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); } else { ExtendedUser32.INSTANCE.SetWindowLong(hWnd, GWL_STYLE, windowState.getStyle()); ExtendedUser32.INSTANCE.SetWindowLong(hWnd, GWL_EXSTYLE, windowState.getExStyle()); ExtendedUser32.INSTANCE.SetWindowPos(hWnd, null, windowState.getLeft(), windowState.getTop(), windowState.getRight() - windowState.getLeft(), windowState.getBottom() - windowState.getTop(), SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); if (windowState.getMaximized()) { ExtendedUser32.INSTANCE.SendMessage(hWnd, User32.WM_SYSCOMMAND, new WPARAM(WinUser.SC_MAXIMIZE), new LPARAM(0)); } } }
/** * On session change. * * @param wParam the w param * @param lParam the l param */ protected void onSessionChange(WinDef.WPARAM wParam, WinDef.LPARAM lParam) { switch (wParam.intValue()) { case Wtsapi32.WTS_SESSION_LOCK: { this.onMachineLocked(lParam.intValue()); break; } case Wtsapi32.WTS_SESSION_UNLOCK: { this.onMachineUnlocked(lParam.intValue()); break; } } }
int WM_CLOSE = 0x10; HWND hwnd = User32.INSTANCE.FindWindow(null, windowTitle); User32.INSTANCE.PostMessage(hwnd, WM_CLOSE, new WinDef.WPARAM(), new WinDef.LPARAM());
public void setDisplaySleep(final boolean sleep) { user32.DefWindowProc( getForegroundWindow().get(), WinUser.WM_SYSCOMMAND, new WinDef.WPARAM(SC_MONITORPOWER), new WinDef.LPARAM(sleep ? 2 : -1) ); }
@Override public void remove() { hide(); super.remove(); User32.User32.PostMessage(WindowsEventDispatch.get(), WM_QUIT, new WPARAM(0), new LPARAM(0)); } };
@Override public synchronized void unhook() { LOG.info("Interrupting keyboard events hook thread"); User32.INSTANCE.PostThreadMessage(keyboardHookThreadID, WinUser.WM_QUIT, new WinDef.WPARAM(), new WinDef.LPARAM()); awaitUtils.waitFor(() -> keyboardHookThreadID == 0, 2000L, () -> LOG.error("Failed to unhook keyboard events in time")); }