屏幕上的客户端矩形坐标 [英] Client rectangle coordinates on screen

查看:97
本文介绍了屏幕上的客户端矩形坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取相对于屏幕的窗口工作区的坐标?

How can I get coordinates of a window's client area relative to screen?

我考虑过使用GetClientRectClientToScreen.另外,在浏览器窗口中,什么是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.

这篇关于屏幕上的客户端矩形坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆