2
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;
4

2 回答 2

5

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

GetClientRect(hWnd, &rec);

GetWindowRect(hWnd, &rec);

从MSDN偷来的,这张图是客户区:

客户区

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

SetWindowPos(hWnd, nullptr, 100, 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
于 2013-06-03T23:55:26.330 回答
4

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

于 2013-06-03T23:53:30.643 回答