【问题标题】:GetWindowRect is not giving left and top values correctly [duplicate]GetWindowRect 没有正确给出左值和上值[重复]
【发布时间】:2020-04-23 00:08:50
【问题描述】:

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

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;

【问题讨论】:

  • GetWindowRect -> GetClientRect
  • 这个question 解释了窗口和客户端矩形之间的区别。

标签: c++ winapi


【解决方案1】:

正如@Richard Critten 建议的那样,使用GetClientRect()GetWindowRect() 返回窗口的屏幕坐标,而GetClientRect() 返回应用程序图形在窗口内的客户区坐标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-22
    • 2020-05-06
    • 2020-06-12
    相关资源
    最近更新 更多