可以先通过所操作窗口对象的 getWindowProperties 接口获取类型为 WindowProperties 的返回值,WindowProperties 中的 windowRect 属性为窗口尺寸,该属性值为一个 Rect 类型的对象,在这种场景下 Rect 中的 width 和 height 提供了所操作窗口的大小,left 和 top 属性提供了所操作窗口的位置。import window from '@ohos.window'; try { let windowClass: window.Window = window.findWindow("test"); let properties = windowClass.getWindowProperties(); } catch (exception) { console.error('Failed to obtain the window properties. Cause: ' + JSON.stringify(exception)); }
可以先通过所操作窗口对象的 getWindowProperties 接口获取类型为 WindowProperties 的返回值,WindowProperties 中的 windowRect 属性为窗口尺寸,该属性值为一个 Rect 类型的对象,在这种场景下 Rect 中的 width 和 height 提供了所操作窗口的大小,left 和 top 属性提供了所操作窗口的位置。