1.设置 DlgTool 属性
style :child (否则界面不在里面)
border : none
主界面属性:
border :resizing(不设置拖动鼠标不能改变大小)
2. 在主界面初始化CNetDemo20Dlg::OnInitDialog() 中添加初始化函数
m_dlgTool.Create(IDD_DLG_TOOL,this);
m_dlgTool.ShowWindow(SW_SHOW);
m_pLive=new CVideoLive();
m_pLive->Create(
NULL,
NULL,
WS_CHILD|WS_VISIBLE,//|WS_EX_TOOLWINDOW,
CRect(0,0,0,0),
this,
5000);
m_pLive->SetSlipMode(4, 0);
3. GetClientRect(&m_clientRect);
AdjWindowSize(m_clientRect);
调用之后就可以显示界面
void CNetDemo20Dlg::AdjWindowSize(CRect &clientrect)
{
CRect rcTool;
rcTool = clientrect;
rcTool.left = rcTool.right - 230;
m_dlgTool.MoveWindow(rcTool);
rcTool.right = rcTool.left;
rcTool.left = clientrect.left;
m_pLive->MoveWindow(rcTool);
}
4. ON_WM_SIZE() 消息
当窗口发生变化时会触发,所以需要先加入消息响应函数
BEGIN_MESSAGE_MAP(CNetDemo20Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_SIZE()
END_MESSAGE_MAP()
并且在.cpp中重构
void CNetDemo20Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if ((cx ==0 && cy == 0) ||
(cx == m_clientRect.Width() && cy == m_clientRect.Height()))
{
return;
}
else if(m_dlgTool.m_hWnd)
{
GetClientRect(&m_clientRect);
AdjWindowSize(m_clientRect);
}
}