Convert CWnd* to myControl*

748 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

try to use :

CEdit *pEdit = reinterpret_cast<CEdit*>(pWnd);
if (pEdit != nullptr)
  // Do something here