![](/img/trans.png)
[英]How can I get a window object from new BrowserWindow() in electron?
[英]Electron: How can I get Screen from BrowserWindow?
我想知道BrowserWindow
位于两个或更多屏幕的位置。 我猜 Electron API 没有给出方法。 我该怎么做? 有什么办法吗??
没有直接的方法可以实现这一点。 但是跟随绝对可以达到您的目的。
let winBounds = window.getBounds();
let whichScreen = screen.getDisplayNearestPoint({x: winBounds.x, y: winBounds.y});
// Returns the screen where your window is located
这经过测试可以正常工作。
创建窗口后,用于检测哪个屏幕中有您的窗口:
const win = new BrowserWindow({...});
使用Screen
API 和getDisplayNearestPoint()
方法,可以获得屏幕坐标:
const winBounds = win.getBounds();
const distScreen = screen.getDisplayNearestPoint({x: winBounds.x, y: winBounds.y})
而且,如果您想获取哪个屏幕内有鼠标光标,请使用:
let cursor = screen.getCursorScreenPoint();
let distScreen = screen.getDisplayNearestPoint({x: cursor.x, y: cursor.y});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.