在mfc中,利用mediaplayer控件编程,窗口缩放的OnSize中:
CRect WindowRvoid CMyPlayer::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);ect;
GetWindowRect(&WindowRect);
((CWnd*)&m_MediaPlayer)->MoveWindow(0,0,WindowRect.Width()-10,WindowRect.Height()-30, TRUE);
}
在另一个窗口中,创建非模态对话框:
if(m_paMyPlaer[i]==NULL)
{
m_paMyPlaer[i] = new CMyPlayer(this);
m_paMyPlaer[i]->Create(CMyPlayer::IDD,GetDesktopWindow());
}
当执行到Create出现如下错误:
File:f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winocc.cpp Line:307
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
原因是:
程序的执行顺序是:(1)构造函数(2)OnSize(3)OnInitDialog
如果在OnSize里面,操作控件,有可能出错(控件可能还没生成):