c++ - Modify the win32 window dragging/moving behavior -
i have child window in parent window. want child window not go out of parent border when drag , move child window.
here current working code in child's callback:
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;
the thing miss when dragging child window on parent border, child window keeps blinking.
it because child window first moved out of border, wm_move
message triggers setwindowpos
.
my question is: how prevent this, maybe overriding mouse drag event?
thanks rbmm, wm_windowposchanging
message need. new working code:
case wm_windowposchanging: windowpos *pos = (windowpos *)lparam; rect rectfather; getwindowrect(hwndfather, &rectfather); if (pos->x < 0) pos->x = 0; if (pos->y < 0) pos->y = 0; if (pos->y > rectfather.bottom - rectfather.top - 341) pos->y = rectfather.bottom - rectfather.top - 341; if (pos->x > rectfather.right - rectfather.left - 110) pos->x = rectfather.right - rectfather.left - 110; break;
Comments
Post a Comment