我正在使用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);
}
}
也许你的窗口不是顶窗,正如文档所示:
例如,当在非顶级窗口上进行函数调用时,它返回FALSE。 https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowdisplayaffinity
你应该像医生说的那样做:
要获取扩展错误信息,请调用GetLastError。