本文介绍了如何从另一个子窗口访问子窗口控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有父窗口,上面有tabControl。然后我在另一个tabControl中显示了另外两个子窗口。在child1中,我有CEdit控件,因此在child2中也是如此。 child2中的CEdit是一个CEdit,它在child1中按下enter按钮时显示来自child1中CEdit的一些文本。问题是每当我点击child1中的输入按钮时,我都会收到错误。我在输入按钮中使用此代码:

I have parent window that has tabControl on it. Then i have made 2 other child window that shown in to that tabControl. In the child1, i have CEdit control and so also in the child2. CEdit in the child2 is a CEdit that show some text from CEdit in the child1 when press enter button in child1. the problem is that whenever i hit the enter button in child1 i get an error. I use this code in enter button :

void child_1::OnBnClickedEnter()
{
    CString CSText;
    m_EnterTextField.GetWindowText(CSText);
    m_View = (CEdit *) GetDlgItem(CE_Child2);//CE_Child2 is the ID from CEdit control in Child2
    m_View->SetWindowText(CSText);//the problem is in here
}



谢谢...:)


thanks... :)

推荐答案

m_View = (CEdit *) child_2->GetDlgItem(CE_Child2);





[更新:详细解决方案]



[UPDATE: Detailed solution]

// child1.h
class child_2; // Forward declaration to avoid including child_2.h

class child_1
{
// ...
public:
    void SetChild2(child_2 *p) { m_child2 = p; }
protected:
    child_2 *m_child2;
}




// child1.cpp
#include <child_2.h>

child_1::child_1(void)
{
    m_child_2 = NULL;
}

void child_1::OnBnClickedEnter()
{
    // Check if SetChild2() has been called and the window is valid.
    ASSERT(m_child2 && ::IsWindow(m_child2->m_hWnd));
    m_View = (CEdit *) m_child2->GetDlgItem(CE_Child2);
}

在child_1和child_2的父对话框的 OnInitDialog()中调用 SetChild2() function。

From within OnInitDialog() of the parent dialog of child_1 and child_2 call the SetChild2() function.



这篇关于如何从另一个子窗口访问子窗口控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:22