iose
iose

Reputation: 47

Java and SetWindowDisplayAffinity

I am using jna.extra.User32Extra library and I have to change windowdisplayaffinity value. Unfortunately the output is always false, I don't know why, and this code doesn't work. I expect WDA_MONITOR makes windows black when print screen

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);
    }
}

Upvotes: 2

Views: 510

Answers (1)

Sascha
Sascha

Reputation: 1343

Maybe your window isn't a top window, as the documentation suggests:

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

You should do as the doc says:

To get extended error information, call GetLastError.

Upvotes: 2

Related Questions