GetWindowRect() 失败,但 IsWindow() 不是 [英] GetWindowRect() fails, but IsWindow() is not

查看:41
本文介绍了GetWindowRect() 失败,但 IsWindow() 不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取外部窗口的大小:

I am trying to get the size of an external window:

POINT point;

point.x = 100;
point.y = 100;

HWND hwnd = WindowFromPoint(point);

LPRECT pRect = {0};
bool ret1 = IsWindow(hwnd);
bool ret = GetWindowRect(hwnd, pRect);

IsWindow 的返回值为真,但 GetWindowRect 失败并出现以下错误:

The return value of IsWindow is true, but GetWindowRect fails with the following error:

1400:无效的窗口句柄

1400: Invalid window handle

有什么问题?

推荐答案

无效的不是窗口句柄,而是您作为第二个参数传递给 GetWindowRect() 的空指针.

It's not the window handle that's invalid, but the null pointer you're passing as the second parameter to GetWindowRect().

LPRECT pRect = {0};

这只是定义了一个 指针RECT 并将指针初始化为 0.您需要提供一个实际的 RECT 结构,如:

This simply defines a pointer to a RECT and initializes the pointer to 0. You need to provide an actual RECT structure, as in:

RECT rc = { 0 };
GetWindowRect(hwnd, &rc);

这篇关于GetWindowRect() 失败,但 IsWindow() 不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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