Java Code Examples for com.sun.jna.platform.win32.WinDef#HWND

The following examples show how to use com.sun.jna.platform.win32.WinDef#HWND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WinUtil.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Forcibly set focus to the given component
 *
 */
public static void requestForeground(Frame frame)
{
	// SetForegroundWindow can't set iconified windows to foreground, so set the
	// frame state to normal first
	frame.setState(Frame.NORMAL);

	User32 user32 = User32.INSTANCE;

	// Windows does not allow any process to set the foreground window, but it will if
	// the process received the last input event. So we send a F22 key event to the process.
	// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setforegroundwindow
	WinUser.INPUT input = new WinUser.INPUT();
	input.type = new WinDef.DWORD(WinUser.INPUT.INPUT_KEYBOARD);
	input.input.ki.wVk = new WinDef.WORD(0x85); // VK_F22
	user32.SendInput(new WinDef.DWORD(1), (WinUser.INPUT[]) input.toArray(1), input.size());

	// Now we may set the foreground window
	WinDef.HWND hwnd = new WinDef.HWND(Native.getComponentPointer(frame));
	user32.SetForegroundWindow(hwnd);
}
 
Example 2
Source File: StageUtils.java    From xJavaFxTool-spring with Apache License 2.0 5 votes vote down vote up
public static void updateStageStyle(Stage stage) {
    if (Platform.isWindows()) {
        Pointer pointer = getWindowPointer(stage);
        WinDef.HWND hwnd = new WinDef.HWND(pointer);

        final User32 user32 = User32.INSTANCE;
        int oldStyle = user32.GetWindowLong(hwnd, WinUser.GWL_STYLE);
        int newStyle = oldStyle | 0x00020000; // WS_MINIMIZEBOX
        user32.SetWindowLong(hwnd, WinUser.GWL_STYLE, newStyle);
    }
}
 
Example 3
Source File: TestOpaque.java    From MercuryTrade with MIT License 5 votes vote down vote up
private static void setTransparent(Component w) {
        WinDef.HWND hwnd = getHWnd(w);
        int wl = User32.INSTANCE.GetWindowLong(hwnd, WinUser.GWL_EXSTYLE);
//        wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
        wl = wl | WinUser.WS_EX_LAYERED | WinUser.WS_EX_TRANSPARENT;
        User32.INSTANCE.SetWindowLong(hwnd, WinUser.GWL_EXSTYLE, wl);
    }
 
Example 4
Source File: FxDemo.java    From java-example with MIT License 5 votes vote down vote up
private long getWindowHandle(Stage stage) {
    long handle = -1;
    try {
    	WinDef.HWND hWnd = User32.INSTANCE.FindWindow(null, WINDOW_TITLE);
    	handle = Pointer.nativeValue(hWnd.getPointer());
    } catch (Throwable e) {
        logger.error("Error getting Window Pointer", e);
    }
    logger.info(String.format("Stage hwnd %d", handle));
    return handle;
}
 
Example 5
Source File: AbstractAdrFrame.java    From MercuryTrade with MIT License 4 votes vote down vote up
private static WinDef.HWND getHWnd(Component w) {
    WinDef.HWND hwnd = new WinDef.HWND();
    hwnd.setPointer(Native.getComponentPointer(w));
    return hwnd;
}
 
Example 6
Source File: TestOpaque.java    From MercuryTrade with MIT License 4 votes vote down vote up
/**
 * Get the window handle from the OS
 */
private static WinDef.HWND getHWnd(Component w) {
    WinDef.HWND hwnd = new WinDef.HWND();
    hwnd.setPointer(Native.getComponentPointer(w));
    return hwnd;
}
 
Example 7
Source File: DesktopService.java    From winthing with Apache License 2.0 4 votes vote down vote up
public Optional<WinDef.HWND> getForegroundWindow() {
    return Optional.ofNullable(user32.GetForegroundWindow());
}
 
Example 8
Source File: DesktopService.java    From winthing with Apache License 2.0 4 votes vote down vote up
public void setForegroundWindow(final WinDef.HWND window) {
    user32.SetForegroundWindow(window);
}
 
Example 9
Source File: DesktopService.java    From winthing with Apache License 2.0 4 votes vote down vote up
public void closeWindow(final WinDef.HWND window) {
    user32.SendMessage(window, WinUser.WM_CLOSE, null, null);
}
 
Example 10
Source File: BrowserComponentStub.java    From HubTurbo with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void focus(WinDef.HWND mainWindowHandle) {
}
 
Example 11
Source File: Test.java    From MercuryTrade with MIT License votes vote down vote up
int GetWindowTextA(WinDef.HWND hWnd, byte[] lpString, int nMaxCount); 
Example 12
Source File: Test.java    From MercuryTrade with MIT License votes vote down vote up
int GetClassNameA(WinDef.HWND hwnd, byte[] lpString,int nMaxCount); 
Example 13
Source File: SetupApi.java    From Flashtool with GNU General Public License v3.0 votes vote down vote up
HDEVINFO SetupDiGetClassDevs(GUID Guid, String Enumerator, WinDef.HWND Parent, int Flags);