CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2016
    Posts
    1

    Moving Parent Dialog while moving Child Dialog MFC

    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.

  2. #2
    Join Date
    Jan 2009
    Posts
    399

    Re: Moving Parent Dialog while moving Child Dialog MFC

    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.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Moving Parent Dialog while moving Child Dialog MFC

    Hopefully, the OP is still waiting an answer...

    Handle WM_MOUSEMOVE in child dialog and do like in the following example:
    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);
        }
    }
    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.
    See:
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Moving Parent Dialog while moving Child Dialog MFC

    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..
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured