【问题标题】:c++ Moving a Window with out changing its sizec ++移动窗口而不改变其大小
【发布时间】:2013-06-03 23:51:11
【问题描述】:
RECT rec;

::GetClientRect(hWnd, &rec);
int windowWidth = rec.right - rec.left, windowHeight = rec.bottom - rec.top;

::printToDebugWindow(windowWidth,windowHeight); //prints 2 numbers

MoveWindow(hWnd,100,100,windowWidth,windowHeight,FALSE);

问题是 windowWidth 和 windowHeight 出于某种原因正在改变。 MoveWindow 似乎正在改变窗口尺寸。并且将 repaint 设置为 TRUE 不会改变任何事情。

输出:

x:560,y:178
x: 544, y: 140
x: 528, y: 102
x: 512, y: 64
x:496,y:26

为什么每次迭代都会改变尺寸?

我也试过了:没有变化

  int windowWidth = rec.right, windowHeight = rec.bottom;

【问题讨论】:

    标签: c++ move


    【解决方案1】:

    您得到的是客户区的大小,而不是窗口的大小。变化:

    GetClientRect(hWnd, &rec);
    

    GetWindowRect(hWnd, &rec);
    

    盗自MSDN,此图为客户区:

    现在我建议忘记这一点并使用SetWindowPos

    SetWindowPos(hWnd, nullptr, 100, 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    

    【讨论】:

      【解决方案2】:

      请改用 SetWindowPos()。它具有允许您告诉系统不要更改大小的标志。 http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-31
        • 1970-01-01
        • 2014-10-29
        • 1970-01-01
        • 2012-08-31
        相关资源
        最近更新 更多