Skip to content

Support “setWindowTop( )” #33

@isinvon

Description

@isinvon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions