为何对ListCtrl控件MoveWindow会出错?
我有以CFromView为基类的CMyView类,在其相当于Dialog的view上有一ListCtrl控件。我希望该控件能随窗口大小改变而改变。
void CmytelView::OnSize(UINT nType, int cx, int cy)
{
CFormView::OnSize(nType, cx, cy);
//TODO:
CListCtrl* p = (CListCtrl*)(this->GetDlgItem(IDC_LIST1));
CRect myRect;
this->GetClientRect(&myRect);
ClientToScreen(&myRect);
p->MoveWindow(myRect.left,myRect.top,myRect.Width() - 10,myRect.Height() - 10,TRUE);
}
Debug时候调用MoveWindow,在其内部出错:
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));//箭头指向这里
if (m_pCtrlSite == NULL)
::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
else
m_pCtrlSite->MoveWindow(x, y, nWidth, nHeight);
}
不知为何出错?运行时还有什么办法可以改变ListCtrl的大小?