JAVAFX怎么获取窗口句柄

caozl 2017-07-11 10:47:06
用javaFx做界面,想用C++来渲染窗口,如何获取窗口句柄?
...全文
840 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
seashoreblue 2017-07-17
  • 打赏
  • 举报
回复
stackoverflow 上还有一种方法,这个我没有试过,你可以一试: private static Pointer getWindowPointer(Stage stage) { try { TKStage tkStage = stage.impl_getPeer(); Method getPlatformWindow = tkStage.getClass().getDeclaredMethod("getPlatformWindow" ); getPlatformWindow.setAccessible(true); Object platformWindow = getPlatformWindow.invoke(tkStage); Method getNativeHandle = platformWindow.getClass().getMethod( "getNativeHandle" ); getNativeHandle.setAccessible(true); Object nativeHandle = getNativeHandle.invoke(platformWindow); return new Pointer((Long) nativeHandle); } catch (Throwable e) { System.err.println("Error getting Window Pointer"); return null; } } 然后 W32API.HWND hwnd = new W32API.HWND(getWindowPointer(stage));
seashoreblue 2017-07-17
  • 打赏
  • 举报
回复
long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow(); Pointer lpVoid = Pointer.createConstant(lhwnd); W32API.HWND hwnd = new W32API.HWND(lpVoid); 前提,需要导入 jna 还有一个 com.sun.jna.examples的包,W32API.HWND 就在这个包下,这个在网上不是很好找,但是花点时间应该找得到。

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧