简体   繁体   中英

How do i move parent dialog when dragging child dialog, in MFC?

Really need some help How do I move the parent dialog when dragging the child dialog?

I have it so that when I drag the parent dialog, the child dialog is also moved, but not the reverse relationship.

Any help would be greatly appreciated, thanks!

My Main dialog.cpp:

void MainDialog::OnMove(int x, int y)
{
    CDialog::OnMove(x, y);
    m_pDialog->SetWindowPos(&wndTop, x, y, 50, 50, SWP_NOZORDER);  // child dialog
}

BEGIN_MESSAGE_MAP(CTranslucentDialog, CDialog)
    //AFX_MSG_MAP
    ON_WM_ERASEBKGND()
    ON_WM_MOVE()
    ON_WM_SIZE()
    ON_WM_CREATE()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

Thanks, I was able to get it to work by creating a handler for NCHITTEST and returning HTTRANSPARENT.

LRESULT CGadgetStandardDialog::OnNcHitTest(CPoint point)
{
    return HTTRANSPARENT;
}

The Problem is that the Mouse Input is consumed by the child. So clicking in a child window and dragging there, usually selects some data in the child (in an edit Control). Or for a static Control the mouse Input is forwarded to the parent.

So you. Need to decide... You always have the posibility to handle this in WM_NCHITTEST and return HTCAPTION, or you allow the parent to handle this in retunring HTTRANSPARENT.

BTW: If you want to implement moving a window with the mouse in the Client area too just handle WM_NCHITTEST and return HTCAPTION. there is no Need to implement a mouse movehandler and doing it by yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM