三种方法,拿项目中的代码来说明:

一:引用传递

二:指针传递

三:获得父窗口

对于三就不多说了,对于一二,看代码便知,引用:

 CGroupAdvance* dlg = new CGroupAdvance(m_OtherListCtr);
 dlg -> DoModal();
 delete dlg;

指针:

 CGroupAdvance* dlg = new CGroupAdvance(&m_OtherListCtr);
 dlg -> DoModal();
 delete dlg;

代码只有有或无&的区别,一个是指针,一个是引用,对应的构造函数也应该做相应变化,对于引用:

CListCtrl&  m_OtherList;//定义成引用,不能定义为CListCtrl  m_OtherList

CGroupAdvance::CGroupAdvance(CListCtrl& tmpListCtr,CWnd* pParent /*=NULL*/)
 : CDialog(CGroupAdvance::IDD, pParent)
 ,m_OtherList(tmpListCtr)//必须在这里初始化
{
}

 

对于指针:

CListCtrl*  m_pOtherList;

CGroupAdvance::CGroupAdvance(CListCtrl* tmpListCtr,CWnd* pParent /*=NULL*/)
 : CDialog(CGroupAdvance::IDD, pParent)
{

m_pOtherList  =  tmpListCtr;

}

 

 优缺点:引用不用判断可用,指针需要判断

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2021-07-20
  • 2022-12-23
  • 2022-01-01
  • 2022-01-26
  • 2022-02-02
  • 2021-09-09
  • 2021-09-27
相关资源
相似解决方案