The
GetDlgItem()
function retrieves a pointer to the specified control or child window inside the window for that the function has been called. You are calling this function from the
child_1
window with an ID that does not exist in this window and the function will return NULL. To get the pointer to a control in another window, you must call
GetDlgItem()
for that other window:
m_View = (CEdit *) child_2->GetDlgItem(CE_Child2);
[UPDATE: Detailed solution]
class child_2;
class child_1
{
public:
void SetChild2(child_2 *p) { m_child2 = p; }
protected:
child_2 *m_child2;
}
#include <child_2.h>
child_1::child_1(void)
{
m_child_2 = NULL;
}
void child_1::OnBnClickedEnter()
{
ASSERT(m_child2 && ::IsWindow(m_child2->m_hWnd));
m_View = (CEdit *) m_child2->GetDlgItem(CE_Child2);
}
From within
OnInitDialog()
of the parent dialog of child_1 and child_2 call the
SetChild2()
function.