我在一个FormView里,自己添加了CListCtrl* m_listCtrl在OnInitialUpdate中初始化了它,并且添加了列、数据等等然后在类的一个方法里想要从尾部添加进列表,所以需要调用GetItemCount()但是他一直报断言错误,m_listCtrl不为空,断言是在::SendMessage(.......)报的求高手救命啊!!!

解决方案 »

  1.   

    我晕为什么自定义的变量(不通过DDX),必须每个方法内都来一遍GetDlgItem ???我在我的方法中最前面加入初始化的语句就行了为什么?!?!?! OnInitialUpdate不行吗? 非要DDX?
      

  2.   

    囧。。头文件: CListCtrl* m_listCtrl;
    构造函数 :m_listCtrl(NULL);OnInitialUpdate:
      m_listCtrl = (CListCtrl*) GetDlgItem(IDC_LIST);
      // do something到此,显示正常foo() {
    //m_listCtrl = (CListCtrl*) GetDlgItem(IDC_LIST); 加上这句就OK
    int index = m_listCtrl->GetItemCount(); // 不加上面这句就报错
    }
      

  3.   

    CWnd* GetDlgItem( int nID ) const;void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;Return ValueA pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL. The returned pointer may be temporary and should not be stored for later use.