WM_SIZE is reactive, WM_SIZING is proactive so I went with the latter. But I got all working, thanks to all! Here is my code, and it works perfectly:
Code:
LRESULT Window::onSizing(WPARAM wParam, LPARAM lParam)
{
RECT sz;
intw, h;
// If the aspect is locked, resize the window equally
if (lockAspect)
{
// Copy over the new size that was determined by windows
memcpy(&sz, (const Void *) lParam, sizeof(RECT));
// Calculate the width and height of the window
w = sz.right - sz.left;
h = sz.bottom - sz.top;
switch (wParam)
{
case WMSZ_LEFT:
case WMSZ_RIGHT:
// Modify the Heigh of the window
sz.bottom = LONG(w * aspectRatio) + sz.top;
break;
case WMSZ_TOP:
case WMSZ_BOTTOM:
// Modify the Width of the window
sz.right = LONG(h * (1 / aspectRatio)) + sz.left;
break;
case WMSZ_TOPRIGHT:
case WMSZ_TOPLEFT:
case WMSZ_BOTTOMRIGHT:
case WMSZ_BOTTOMLEFT:
// Adjust the width and height of the window to match aspect ratio
if (float(h) / float(w) > aspectRatio)
{
w = int(float(h) / aspectRatio);
}else{
h = int(float(w) * aspectRatio);
}
// Adjust Height
if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOPRIGHT)
{
sz.top = sz.bottom - h;
}else{
sz.bottom = sz.top + h;
}
// Adjust Width
if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_BOTTOMLEFT)
{
sz.left = sz.right - w;
}else{
sz.right = sz.left + w;
}
break;
}
// Copy back the size of the window
memcpy((Void *) lParam, &sz, sizeof(RECT));
return TRUE;
}
return FALSE;
}