当拖动第一个对话框时,后两个对话框实时自动排列,暂时未去改变它们的大小,只是让它们紧贴第一个对话框来调整位置
代码段贴在下面,欢迎大家参与讨论
主对话框的源文件中
CRect rect[24];//矩形
CDlgVideo *pDlgVideo[24];//子对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
==================================
BOOL CMySoftDlg::OnInitDialog()
{
。。。。。。
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//在这儿动态创建几个视频窗口,然后模拟拖动来进行自动吸附排列
pDlgVideo[0] = new CDlgVideo(this);
pDlgVideo[0]->Create(IDD_DIALOG_VIDEO,this);
pDlgVideo[0]->ShowWindow(SW_SHOW);
pDlgVideo[0]->MoveWindow(0,0,400,300);
pDlgVideo[1] = new CDlgVideo(this);
pDlgVideo[1]->Create(IDD_DIALOG_VIDEO,this);
pDlgVideo[1]->ShowWindow(SW_SHOW);
pDlgVideo[1]->MoveWindow(300,0,200,150);
pDlgVideo[2] = new CDlgVideo(this);
pDlgVideo[2]->Create(IDD_DIALOG_VIDEO,this);
pDlgVideo[2]->ShowWindow(SW_SHOW);
pDlgVideo[2]->MoveWindow(300,0,200,150);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMySoftDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// CRect rect[24];
// CDlgVideo *pDlgVideo[24];
pDlgVideo[0]->GetWindowRect(&rect[0]);
ScreenToClient(&rect[0]);
pDlgVideo[1]->MoveWindow(rect[0].right,0,200,150);//移动子窗口
pDlgVideo[1]->GetWindowRect(&rect[1]);
ScreenToClient(&rect[1]);
pDlgVideo[2]->MoveWindow(rect[0].right,rect[1].bottom,200,150);//移动子窗口
this->Invalidate(FALSE);
CDialog::OnLButtonUp(nFlags, point);
}
================================
//子对话框的源文件中:
void CDlgVideo::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
//AfxMessageBox("尺寸改变了");
AfxGetApp()->m_pMainWnd->PostMessage(WM_LBUTTONUP,0,0);//实现主对话框更新布局
/*本来是想在拖动结束时,捕获释放鼠标左键的消息,但实际上,并捕获不到,所以在这个小对话框的OnSize中人为的发送一个左键释放的消息,当然也可以自定义一个消息,这儿是偷个懒了*/
}
//
一个消息必须由一个窗口接收。在窗口的过程(WNDPROC)中可以对消息进行分析,对自己感兴趣的消息进行处理。系统通过窗口句柄来在整个系统中唯一标识一个窗口,发送一个消息时必须指定一个窗口句柄表明该消息由那个窗口接收。而每个窗口都会有自己的窗口过程,所以用户的输入就会被正确的处理。
评论