Thanks for the comments!
@iMalc "The fact that your real code will actually be doing something useful will mean that overall it wont be spending quite as much time sleeping."
Yes i didnt realize that, my bad.
@BMJ
Code:
void ShakeIt()
{
RECT rcWndSz;
int iX = 0;
int iY = 0;
int iScreenX = GetSystemMetrics(SM_CXSCREEN);
int iScreenY = GetSystemMetrics(SM_CYSCREEN);
DWORD oldtick = GetTickCount();
while (1)
{
if (GetWindowRect(hWnd, &rcWndSz))
{
iX = rcWndSz.left + ((rand() % 5) * ((rand() % 100) > 50 ? 1 : -1));
iY = rcWndSz.top + ((rand() % 5) * ((rand() % 100) > 50 ? 1 : -1));
iX = iX > iScreenX ? iScreenX : iX;
iY = iY > iScreenY ? iScreenY : iY;
iX = iX < 0 ? 0 : iX;
iY = iY < 0 ? 0 : iY;
SetWindowPos(hWnd, NULL, iX, iY, 0, 0, SWP_NOSIZE);
Sleep(20);
}
if ((GetTickCount() - oldtick)> 3000) break;
}
}