GetWindowRect()
时间: 2024-06-12 10:09:28 浏览: 3
GetWindowRect() 函数是一个 Windows API 函数,用于获取窗口的位置和尺寸信息。它的函数原型如下:
BOOL GetWindowRect(HWND hWnd, LPRECT lpRect);
参数说明:
- hWnd:要获取信息的窗口句柄。
- lpRect:指向一个RECT结构的指针,用于接收窗口的位置和尺寸信息。
该函数的返回值为BOOL类型,成功时返回非零值,失败时返回零。
相关问题
GetWindowRect
GetWindowRect是一个Windows API函数,用于获取指定窗口的位置和大小信息。
GetWindowRect函数的声明如下:
```
BOOL GetWindowRect(HWND hWnd, LPRECT lpRect);
```
参数说明:
- hWnd: 窗口句柄,表示要获取信息的窗口。
- lpRect: 指向一个RECT结构体的指针,用于接收窗口的位置和大小信息。
RECT结构体定义如下:
```
typedef struct _RECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT, *PRECT, *NPRECT, *LPRECT;
```
RECT结构体包含了窗口的左上角和右下角坐标,通过计算可以得到窗口的宽度和高度。
vs中GetWindowRect
在Visual Studio中,GetWindowRect是一个函数,用于获取指定窗口的位置和大小信息。这个函数可以用来获取任何一个窗口的矩形区域。
GetWindowRect函数的声明如下:
```cpp
BOOL GetWindowRect(HWND hWnd, LPRECT lpRect);
```
其中,hWnd是要获取位置和大小信息的窗口的句柄,lpRect是一个指向RECT结构的指针,用来接收窗口的位置和大小信息。
调用GetWindowRect函数后,会将窗口的左上角和右下角的坐标存储在lpRect所指向的RECT结构中。
示例代码如下:
```cpp
#include <Windows.h>
int main()
{
HWND hWnd = GetForegroundWindow(); // 获取当前活动窗口的句柄
RECT rect;
GetWindowRect(hWnd, &rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
printf("Window Rect: left=%d, top=%d, right=%d, bottom=%d\n", rect.left, rect.top, rect.right, rect.bottom);
printf("Window Width: %d, Height: %d\n", width, height);
return 0;
}
```
上述示例代码中使用GetForegroundWindow函数获取当前活动窗口的句柄,然后调用GetWindowRect函数获取该窗口的位置和大小信息,并打印出来。
希望能对您有所帮助,如果还有其他问题,请随时提问。