栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

JavaFX最小化未修饰的阶段

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JavaFX最小化未修饰的阶段

您可以只设置适当的窗口样式。它可以在XP中运行,但在Windows 7 32位环境中应该可以。我认为(但无法测试)是否使用64位,然后更改为Ptr
Windows函数,即。GetWindowLongPtr。

import com.sun.jna.Native;import com.sun.jna.Pointer;import com.sun.jna.platform.win32.User32;import com.sun.jna.platform.win32.WinDef.HWND;import com.sun.jna.platform.win32.WinUser;import static com.sun.jna.platform.win32.WinUser.GWL_STYLE;import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.control.textarea;import javafx.scene.layout.VBox;import javafx.stage.Stage;public class JNATest extends Application {    public static void main(String[] args) { launch(args); }    @Override    public void start(Stage stage) {        textarea ta = new textarea("outputn");        VBox root = new VBox(5,ta);        Scene scene = new Scene(root,800,200);        stage.setTitle("Find this window");        stage.setScene(scene);        stage.show();        //gets this window (stage)        long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow();        Pointer lpVoid = new Pointer(lhwnd);        //gets the foreground (focused) window        final User32 user32 = User32.INSTANCE;        char[] windowText = new char[512];        HWND hwnd = user32.GetForegroundWindow();        //see what the title is        user32.GetWindowText(hwnd, windowText, 512);        //user32.GetWindowText(new HWND(lpVoid), windowText, 512);//to use the hwnd from stage        String text=(Native.toString(windowText));        //see if it's the same pointer        ta.appendText("HWND java:" + lpVoid + " HWND user32:"+hwnd+" text:"+text+"n");        //change the window style if it's the right title        if (text.equals(stage.getTitle())){ //the style to change  int WS_DLGframe = 0x00400000;//s/b long I think //not the same constant here?? ta.appendText("windows api:"+WS_DLGframe+" JNA: "+WinUser.SM_CXDLGframe); int oldStyle = user32.GetWindowLong(hwnd, GWL_STYLE); int newStyle = oldStyle & ~0x00400000; //bitwise not WS_DLGframe means remove the style newStyle = newStyle & ~0x00040000;//WS_THICKframe    user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);        }    }}

我的猜测是您将最后3行替换为

 long oldStyleLong = user32.GetWindowLongPtr(hwnd, GWL_STYLE).longValue(); long newStyleLong = oldStyleLong & ~ 0x00400000l; user32.SetWindowLongPtr(hwnd, GWL_STYLE, new baseTSD.LONG_PTR(newStyleLong));

为64位。我认为我的User32.dll中没有这些功能,因此无法对其进行测试。那里有很多无关的代码,主要用于测试或教学。确定要执行的操作后,请删除未使用的行。

ps。不要添加

newStyle = newStyle &~0x00020000;//WS_MINIMIZEBOX
。这是JavaFX不用于修饰的样式标志之一。这就是为什么最小化不可用的原因。也许如果您尝试将舞台设置为未修饰状态并添加(使用|,而不是&〜)最小化框标志,您将获得相同的结果。有一些工具可以从任何窗口查找所有样式标记。

这是使用阶段的HWND更改未装饰阶段的最简单的代码。

    public void start(Stage stage) {        Scene scene = new Scene(new Pane(new Label("Hello World")));        stage.initStyle(StageStyle.UNDECORATED);        stage.setTitle("Find this window");        stage.setScene(scene);        stage.show();        long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow();        Pointer lpVoid = new Pointer(lhwnd);        HWND hwnd = new HWND(lpVoid);        final User32 user32 = User32.INSTANCE;        int oldStyle = user32.GetWindowLong(hwnd, GWL_STYLE);        System.out.println(Integer.toBinaryString(oldStyle));        int newStyle = oldStyle | 0x00020000;//WS_MINIMIZEBOX        System.out.println(Integer.toBinaryString(newStyle));        user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);    }

它可以在前后打印出样式标记,以便您查找设置了哪些样式。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437796.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号