简体   繁体   English

在MFC中拖动子对话框时如何移动父对话框?

[英]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. 谢谢,我能够通过为NCHITTEST创建处理程序并返回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. 需要决定...你总是有能力在WM_NCHITTEST中处理它并返回HTCAPTION,或者你允许父进程在重新调整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. 顺便说一句:如果你想在客户区使用鼠标移动窗口,那么只需处理WM_NCHITTEST并返回HTCAPTION。 there is no Need to implement a mouse movehandler and doing it by yourself. 没有必要实现鼠标移动处理程序并自己完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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