我在父窗口中有一個子窗口。 當我拖動並移動子窗口時,我希望子窗口不會超出父邊框。修改win32窗口拖/移動行爲
這裏是孩子的回調我當前的工作代碼:
case WM_MOVE:
RECT rect = getLocalCoordinates(hWnd);
RECT rectFather;
GetWindowRect(hWndFather, &rectFather);
if (rect.left < 0)
rect.left = 0;
if (rect.top < 0)
rect.top = 0;
if (rect.bottom > rectFather.bottom - rectFather.top - 60)
rect.top = rectFather.bottom - rectFather.top - 341;
if (rect.right > rectFather.right - rectFather.left - 35)
rect.left = rectFather.right - rectFather.left - 110;
SetWindowPos(hWnd, NULL,rect.left, rect.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
break;
我錯過的唯一的事情就是在父邊境拖着子窗口時,子窗口不斷閃爍。
這是因爲子窗口第一次移出邊界,比WM_MOVE
消息觸發我的SetWindowPos
。
我的問題是:我怎麼能阻止這個,也許通過重寫鼠標拖動事件?
你需要處理WM_WINDOWPOSCHANGING – RbMm