遇到件怪事,我在 void CDialogBarEx::OnPaint()  中  获得了一个CEdit 的指针 p_edit  = (CEdit*)this->GetDlgItem(IDC_MYEDIT1);其中 p_edit 为一个保护型的成员变量,但是不知道为什么,当程序在成员函数void CDialogBarEx::OnMyradio3() 中运行时,p_edit的值改变了,但是我并没有对其值做任何修改啊。照理说同一个类的成员变量值应该是不变的啊,为什么呢?

解决方案 »

  1.   

    A CWnd* pointer address can change, and also you are getting it in OnPaint() which can be called many times, try to keep a HWND variabale around:HWND m_hwnd;m_hwnd = this->GetDlgItem(IDC_MYEDIT1)->GetSafeHwnd();then in other places, do
    CWnd* pWnd = CWnd::FromHandle( m_hwnd  );
      

  2.   

    saucer(思归)  you mean the pointer address of a control may change, while the handle of the same control will not? I dont know whether I get it in the right way.
      

  3.   

    anytime you call GetDlgItem(IDC_MYEDIT1), the system just creates a CWnd* for you, so the pointer can change from one call to the next the documentation says:************************
    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.************************