问题描述
如何获取相对于屏幕的窗口工作区的坐标?
How can I get coordinates of a window's client area relative to screen?
我考虑过使用GetClientRect
和ClientToScreen
.另外,在浏览器窗口中,什么是ClientRect
?仅显示带有HTML
文档的矩形,或者它包含浏览器栏和弹出菜单,它们可能会缩小HTML
文档的尺寸?
I thought about using GetClientRect
and ClientToScreen
. Also, in a browser window what is ClientRect
? Only rectangle with HTML
document shown in it, or it includes browser bars and pop-up menus, that can possibly shrink dimension for HTML
doc?
我已经尝试过了:
HWND hWnd;
RECT rc;
if (GetClientRect(hWnd, &rc)) // get client coords
{
MapWindowPoints(hWnd, NULL, reinterpret_cast<POINT*>(&rc), 2); // converts rect rc points
return rc.top;
}
但是可悲的是,浏览器的客户端矩形包含所有这些弹出式浏览器菜单和栏,因此不能用于检测浏览器HTML文档空间的准确坐标.如果有人对如何完成操作有任何建议,请尝试一下.
But the sad thing is that browser's client rectangle includes all those pop-up browser menus and bars, therefore can't be used to detect accurate coordinates of browsers HTML document space. If anyone got suggestions how it can be done, will try it gladly.
推荐答案
是的,您可以使用ClientToScreen
函数来做到这一点:
Yes, you can do this with the ClientToScreen
function:
RECT rc;
GetClientRect(hWnd, &rc); // get client coords
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&rc.left)); // convert top-left
ClientToScreen(hWnd, reinterpret_cast<POINT*>(&rc.right)); // convert bottom-right
什么是浏览器中的客户端"矩形取决于浏览器的实现.您可以使用Spy ++自己发现它.
What is the "client" rectangle in a browser depends on the browser implementation. You can use Spy++ to discover this for yourself.
这篇关于屏幕上的客户端矩形坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!