我正在使用 jna.extra.User32Extra 库,我必须更改 windowdisplayaffinity 值。 不幸的是,输出总是错误的,我不知道为什么,并且这段代码不起作用。我希望 WDA_MONITOR 在打印屏幕时使窗口变黑
public class Browser extends Application {
@Override
public void start(Stage stage) throws Exception {
StackPane pane = new StackPane();
WebView view = new WebView();
WebEngine engine = view.getEngine();
engine.load("https://google.com");
pane.getChildren().add(view);
Scene scene = new Scene(pane, 1280, 720);
stage.setTitle("Browser JAVA");
stage.setScene(scene);
WinDef.HWND hWnd = User32.INSTANCE.FindWindow(null, "");
boolean output = User32Extra.INSTANCE.SetWindowDisplayAffinity(hWnd, 1);
System.out.println("output "+output);//false
stage.show();
}
public static void main(String[] args) throws IOException {
Application.launch(args);
}
}
最佳答案
也许您的窗口不是顶部窗口,如文档所示:
it returns FALSE when, for example, the function call is made on a non top-level window. https://learn.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowdisplayaffinity
你应该按照文档所说的去做:
To get extended error information, call GetLastError.
关于Java 和 SetWindowDisplayAffinity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55740104/