如何从 hWnd 获取监视器屏幕分辨率? [英] How to get the Monitor Screen Resolution from a hWnd?
问题描述
如何从 hWnd 获取显示器屏幕分辨率?
How to get the monitor screen resolution from a hWnd?
我使用的是 hWnd,因为窗口可以位于多个显示器中的任何一个.
I am using a hWnd because the window could be located on any one of multiple monitors.
即hWnd 上/左坐标位于屏幕分辨率为 800 x 600 的显示器上.
i.e. the hWnd top/left coordinate is on a Monitor that has a Screen Resolution of 800 x 600.
我用一种叫做 PL/B 的语言编程,它允许调用 Windows API.
I program in a language called PL/B and it allows calling Windows API.
可以使用哪些 Window API?
What Window APIs can be used?
推荐答案
user32
函数 MonitorFromWindow 允许您传入一个 hwnd,并返回它所在的监视器的句柄(或默认值 - 有关详细信息,请参阅链接的 MSDN 文章).有了它,您可以调用 GetMonitorInfo 来检索MONITORINFO 结构,其中包含 RECT 详细信息其分辨率.
The user32
function MonitorFromWindow allows you to pass in an hwnd, and returns a handle to the monitor it's on (or a default - see the linked MSDN article for details). With that you can call GetMonitorInfo to retrieve a MONITORINFO struct which contains a RECT detailing its resolution.
请参阅多屏幕参考有关详细信息,请参阅 MSDN 部分.
See the Multiple Screens Reference section of MSDN for more details.
我会添加示例代码,但我不知道您引用的语言,也不知道 C# 示例代码对您有多大用处.如果您认为它会有所帮助,请告诉我,我会很快编写一些代码.
I'd add example code but I don't know the language you referenced, and I don't know how useful C# example code would be to you. If you think it'll help, let me know and I'll code up something real quick.
这篇关于如何从 hWnd 获取监视器屏幕分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!