我正在为我的游戏实施窗口限制,我遇到了一个小问题。
我使用此代码设置约束:
case WM_GETMINMAXINFO:
{
LPMINMAXINFO p_info = (LPMINMAXINFO)lParam;
RECT wRect;
RECT cRect;
int wWidth;
int wHeight;
int cWidth;
int cHeight;
int total_border_width;
int total_border_height;
POINT wmin, wmax;
GetWindowRect(hWnd, &wRect);
GetClientRect(hWnd, &cRect);
wWidth = wRect.right - wRect.left;
wHeight = wRect.bottom - wRect.top;
cWidth = cRect.right - cRect.left;
cHeight = cRect.bottom - cRect.top;
total_border_width = wWidth - cWidth;
total_border_height = wHeight - cHeight;
wmin.x = (d->min_w > 0) ? d->min_w + (resize_is_restore ? -total_border_width : total_border_width) : p_info->ptMinTrackSize.x;
wmin.y = (d->min_h > 0) ? d->min_h + total_border_height : p_info->ptMinTrackSize.y;
wmax.x = (d->max_w > 0) ? d->max_w + total_border_width : p_info->ptMaxTrackSize.x;
wmax.y = (d->max_h > 0) ? d->max_h + total_border_height : p_info->ptMaxTrackSize.y;
p_info->ptMinTrackSize = wmin;
p_info->ptMaxTrackSize = wmax;
resize_is_restore = false;
}
break;
问题是当窗口恢复时没有遵守min_w约束。
我想在这种情况下我需要否定总宽度:
wmin.x = (d->min_w > 0) ? d->min_w + (resize_is_restore ? -total_border_width : total_border_width) : p_info->ptMinTrackSize.x;
不幸的是,我无法设置resize_is_restore,因为WM_SIZE消息是在WM_GETMINMAXINFO之后发送的。有没有办法在设置minmaxinfo之前发现调整大小是由于恢复?
由于
修正了:
/* Fix for when the window is restored */
if (cWidth == 0 && cHeight == 0) {
break;
}