Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support “setWindowTop( )” #33

Open
isinvon opened this issue Oct 28, 2024 · 0 comments
Open

Support “setWindowTop( )” #33

isinvon opened this issue Oct 28, 2024 · 0 comments

Comments

@isinvon
Copy link

isinvon commented Oct 28, 2024

I wrote a plan , hope will be useful to you.

depandency

<dependency>
      <groupId>net.java.dev.jna</groupId>
      <artifactId>jna</artifactId>
      <version>5.15.0</version> 
  </dependency>

WindowTopUtil.java

package com.sinvon.api.utils;

import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;

public class WindowTopUtil {

    // Topmost window handle
    public static final WinDef.HWND HWND_TOPMOST = new WinDef.HWND(new Pointer(-1));

    public static void setWindowTop(String windowTitle) {
        if (windowTitle == null || windowTitle.isEmpty()) {
            System.out.println("The provided window title is null or empty; unable to set the window to topmost."); // debug
            return;
        }

        User32 user32 = User32.INSTANCE;

        // Find window handle
        WinDef.HWND hWnd = user32.FindWindow(null, windowTitle);

        if (hWnd == null) {
            System.out.println("Failed to retrieve the window handle; unable to set the window to topmost.");
            return;
        }

        // Set window to topmost
        user32.SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, User32.SWP_NOMOVE | User32.SWP_NOSIZE);
    }
}

main.java

// set window title
String windowTitle = "My Webview App"; 
wv.setTitle(windowTitle);

// set WebView Window Top
WindowTopUtil.setWindowTop(windowTitle);

it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant