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);

The problem is that the windowWidth and windowHeight are changing for some reason. MoveWindow seems to be changing the windows dimensions. and setting repaint to TRUE changes nothing.

outPut:

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

why are the dimensions changing every iteration?

i also tryed: No change

  int windowWidth = rec.right, windowHeight = rec.bottom;
Anthony Raimondo
  • 1,621
  • 2
  • 24
  • 40

2 Answers2

5

You're getting the size of the client area, not the window. Change:

GetClientRect(hWnd, &rec);

to

GetWindowRect(hWnd, &rec);

Stolen from MSDN, this picture shows the client area:

client area

Now I would suggest just forgetting about that and using SetWindowPos:

SetWindowPos(hWnd, nullptr, 100, 100, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
chris
  • 60,560
  • 13
  • 143
  • 205
4

Use SetWindowPos() instead. It has flags that allow you to tell the system to not change the size. http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

David
  • 4,744
  • 5
  • 33
  • 64