How to move the parent Dialog while moving the child dialog.
Child Dialog is shown infront of parent and covers the parent dialog. I want to move the parent while child is moving so that parent is just invisible to the user.
Printable View
How to move the parent Dialog while moving the child dialog.
Child Dialog is shown infront of parent and covers the parent dialog. I want to move the parent while child is moving so that parent is just invisible to the user.
Please detail you issue: what kind of app is (Dialog based, MDI, etc.), and child window are modal, are spread whole screen, etc. Then, you get some answers.
Hopefully, the OP is still waiting an answer... :)
Handle WM_MOUSEMOVE in child dialog and do like in the following example:
NOTE: it's not clear if you refer to a child dialog (having WS_CHILD / WC_CHILDWINDOW style set) or a top-level dialog which can have or can have not an owner but has never a parent.Code:void CChildDialog::OnMouseMove(UINT nFlags, CPoint point)
{
__super::OnMouseMove(nFlags, point);
CWnd* pWndParent = GetParent();
ASSERT_VALID(pWndParent);
ClientToScreen(&point);
if (DragDetect(point))
{
CPoint pointNew;
::GetCursorPos(&pointNew);
CRect rcParent;
pWndParent->GetWindowRect(rcParent);
pWndParent->SetWindowPos(NULL,
rcParent.left + (pointNew.x - point.x),
rcParent.top + (pointNew.y - point.y),
0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
}
See:
Another (but almost similar) way is handling WM_WINDOWPOSCHANGED (or WM_WINDOWPOSCHANGING) message and check the absence of SWP_NOMOVE flag... Then - move the parent window the same way as Ovidiu suggested for his solution (the call DragDetect(...) won't be needed in that case).
Note that this solution will also work for the case when the child dialog would be moved using some code..