GetWindowRect 未正确给出左值和顶部值

GetWindowRect is not giving left and top values correctly

本文关键字:顶部 GetWindowRect      更新时间:2023-10-16

我正在尝试更改我的窗口背景,但函数 GetWindowRect 没有正确获取左侧和顶部值。FillRect 函数仅填充屏幕的四分之一,其余部分保持透明。当我手动设置左侧和顶部值时,它可以正常工作,填满整个窗口。

case WM_ERASEBKGND:{
hdc = BeginPaint(hwnd, &ps);
RECT rect;
GetWindowRect(hwnd, &rect);
rect.left = 0; //It only works
rect.top = 0;  //if I do this
FillRect(hdc, &rect, CreateSolidBrush(RGB(240,240,240));
EndPaint(hwnd, &ps);
}
break;

正如@Richard Critten建议的那样,使用GetClientRect().GetWindowRect()返回窗口的屏幕坐标,而GetClientRect()返回呈现应用程序图形的窗口中工作区的坐标。