如何让 CreateWindowEx() 在特定监视器上创建窗口?

发布于 2024-08-13 09:14:11 字数 122 浏览 2 评论 0原文

我确定可以使用 GetSystemMetrics(SM_CMONITORS) 查询连接的监视器的数量,但是有什么方法可以控制 CreateWindowEx() 用于窗口的监视器?

I've determined that I can use GetSystemMetrics(SM_CMONITORS) to query the number of attached monitors, but is there any way to control what monitor CreateWindowEx() uses for the window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薄荷梦 2024-08-20 09:14:12

是的,通过“x”和“y”参数。使用 EnumDisplayMonitors(传递两个空值)来枚举监视器。您的 MonitorEnumProc 回调获取监视器显示矩形的 RECT*。如果显示器位于主显示器的左侧,您将得到负的 RECT.right。

Yes, by the "x" and "y" arguments. Use EnumDisplayMonitors (pass two nulls) to enumerate the monitors. Your MonitorEnumProc callback gets a RECT* to the monitor's display rectangle. You'd get a negative RECT.right if a monitor is located at the left of your main one.

白日梦 2024-08-20 09:14:12

每个监视器仅显示桌面的某些部分,因此在特定监视器上显示窗口只需将窗口移动到该监视器显示的桌面部分即可。当您调用 CreateWindowEx(或 CreateWindow)时,您可以指定窗口的 x 和 y 坐标,因此在特定监视器上显示它仅意味着指定落在该监视器显示区域内的坐标。

您可以使用 GetMonitorInfo 查找系统上监视器的工作区域。

Each monitor simply displays some part of the desktop, so showing the window on a particular monitor is a matter of moving the window to the part of the desktop displayed by that monitor. When you call CreateWindowEx (or CreateWindow) you can specify x and y coordinates for the window, so displaying it on a particular monitor simply means specifying coordinates that fall within the area displayed by that monitor.

You can find the work areas for the monitors on a system with GetMonitorInfo.

我不会写诗 2024-08-20 09:14:12

x 和 y 参数指定新窗口的位置。该点可以位于虚拟屏幕上的任何位置(所有监视器矩形的组合)。

如果您想在同一显示器上创建另一个窗口,您可以调用 MonitorFromWindow。否则可以使用 枚举所有监视器EnumDisplayMonitors

无论哪种方式,一旦您拥有 HMONITOR 句柄,您就必须调用 GetMonitorInfo。您的 x 和 y 参数应该是监视器信息结构中 rcWork 成员范围内的值。您通常会选择将窗口置于该矩形中心的值。

使用工作区矩形而不是完整的监视器矩形很重要,因为您不希望窗口出现在任务栏和其他始终位于顶部的应用程序栏下方。

The x and y parameters specify the location of the new window. This point can be anywhere on the virtual screen (all the monitor rectangles combined).

If you want to create the window on the same monitor as another window you can call MonitorFromWindow. Otherwise can enumerate all the monitors with EnumDisplayMonitors.

Either way, once you have a HMONITOR handle you must then call GetMonitorInfo. Your x and y parameters should be a value inside the bounds of the rcWork member in the monitor info struct. You would normally choose values that puts your window in the center of this rectangle.

It is important to use the workarea rectangle and not the full monitor rectangle because you don't want your window to appear underneath the Taskbar and other always-on-top appbars.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文