gpt4 book ai didi

c++ - 从 Window Rect 计算客户端大小和位置

转载 作者:行者123 更新时间:2023-11-28 04:43:56 25 4
gpt4 key购买 nike

如何使用 window rect 获取客户端大小和位置?这可能吗?

最佳答案

不确定您到底想找出什么。也许尝试这样的事情:

#include <iostream>
#include <windows.h>

int main()
{
RECT r;
HWND h = GetConsoleWindow(); // or whatever window needed

GetWindowRect(h, &r);
std::cout << "Relative Client X,Y: " << r.left << "," << r.top << std::endl;
std::cout << "Relative Client W,H: " << r.right - r.left << "," << r.bottom - r.top << std::endl;

GetClientRect(h, &r);
std::cout << "Client X,Y: " << r.left << "," << r.top << std::endl;
std::cout << "Client W,H: " << r.right - r.left << "," << r.bottom - r.top << std::endl;
}

例如:

Relative Client X,Y: 100,100
Relative Client W,H: 947,594
Client X,Y: 0,0
Client W,H: 910,552

和/或如果你想获得客户区相对于屏幕的位置,你可以使用ClientToScreen功能。例如:

#include <windows.h>

int main()
{
HWND h = GetConsoleWindow(); // or provided HWND
POINT p{}; // defaulted to 0,0 which is always left and top of client area

ClientToScreen(h, &p);
SetCursorPos(p.x, p.y); // places cursor to the 0,0 of the client
}

关于c++ - 从 Window Rect 计算客户端大小和位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49673503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com