listCtrl控件自动适应窗口大小

形式1:用于在单文档窗口中,或者是手动创建的listctrl

void CTrade_MISView::OnSize(UINT nType, int cx, int cy) {  CView::OnSize(nType, cx, cy);  // TODO: Add your message handler code here  if (m_ListCtrl)    //m_ListCtrl是listctrl的实例对象  {   CRect rect;      GetClientRect(rect);  //直接获取用户区rect   rect.top += 30; //这里是设置距离顶部30像素   m_ListCtrl.MoveWindow(rect);  } }

 形式2:用于在对话框窗口中

void CDlglistDlg::OnSize(UINT nType, int cx, int cy) {  CDialog::OnSize(nType, cx, cy);  // TODO: Add your message handler code here        CWnd  *pList=GetDlgItem(IDC_LIST1);    if(pList)    {    CRect  rect;   GetWindowRect(&rect);  //获取窗口rect,   ScreenToClient(rect);  //从窗口尺寸转换到用户区rect   pList->MoveWindow(&rect,true);    }    } 形式3:也是用于单文档的,或者是自己手动创建的listctrl,不过这种方法还有待考证

void ClistcontrolView::OnSize(UINT nType, int cx, int cy) {  CView::OnSize(nType, cx, cy);

 // TODO: 在此处添加消息处理程序代码  if(m_ListCtrl)   //m_ListCtrl是listctrl的实例对象  {   m_ListCtrl.MoveWindow(0,30,cx,cy); //重置LIST大小  }

}

posted @ 2013-11-01 16:23  t.travis  阅读(516)  评论(0)    收藏  举报