c++castingmfccontrolscwnd

Convert CWnd* to myControl*


I am trying to convert a CWnd* pointer to a custom control pointer. The custom control just extends CEdit. Below is what I have. pWnd was passed in. it is a CWnd*.

calEdit* test = (calEdit*)pWnd->GetDlgItem(pWnd->GetDlgCtrlID());

When I try to debug and see what the value of test is, none of its members can be evaluated. The CWnd* is definitely not the problem.

To be sure that the CWnd* is pointing to the control I want, I did pWnd->GetDlgCtrlID(), and the ID matches the expected control.


Solution

  • try to use CEdit *pEdit = dynamic_cast<CEdit*>(pWnd)