c ++移动窗口而不改变其大小

Ant*_*ndo 2 c++ move

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);
Run Code Online (Sandbox Code Playgroud)

问题是 windowWidth 和 windowHeight 由于某种原因正在改变。MoveWindow 似乎正在改变窗口尺寸。并将重绘设置为 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;
Run Code Online (Sandbox Code Playgroud)

chr*_*ris 5

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

GetClientRect(hWnd, &rec);
Run Code Online (Sandbox Code Playgroud)

GetWindowRect(hWnd, &rec);
Run Code Online (Sandbox Code Playgroud)

盗自MSDN,此图为客户区:

客户区

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

SetWindowPos(hWnd, nullptr, 100, 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
Run Code Online (Sandbox Code Playgroud)