使用父对话框中的函数发送字符串 [英] Using a function in parent dialog to send a string
问题描述
嗨专家,
我正在使用VC ++ 6.0和MFC来创建基于对话框的应用程序。我无法在父对话框中使用函数从任何子对话框发送字符串并将其显示在父对话框中。我的子对话框是在父对话框的CTabCtrl中创建的。
然而它会返回此错误:
调试断言失败!
程序:D \:.. \..\Debug \ MyDialog.exe
文件:winocc.cpp
行:259
请指教。谢谢。
mraaf
我尝试了什么:
这是我需要从子对话框中调用的函数 - 使用它从子节点发送字符串并将其显示在父节点的编辑框中:
Hi Experts,
I'm using VC++ 6.0 with MFC to create a dialog based application. I have trouble to use a function in parent dialog to send string from any of the child dialogs and show it in the parent. My child dialogs are created inside a CTabCtrl on the parent dialog.
It however returns this error:
Debug Assertion Failed!
Program:D\:..\..\Debug\MyDialog.exe
File: winocc.cpp
Line: 259
Please advise. Thank you.
mraaf
What I have tried:
This is the function I need to call from a child dialog - using this to send string from child and display it in an edit box in the parent:
void CParentDlg::GetEvent(LPCTSTR pEvent)
{
m_editEvent.SetWindowText(pEvent);
}
然后我从一个带标签的子对话框中调用上面的函数:< br $>
Then I called above function from one of the tabbed child dialog:
void CChildDlg1::OnCheckPower24v()
{
CParentDlg parent;
parent.GetEvent("ACTIVATE 24V");
}
推荐答案
您正在使用未分配的变量parent
。
试试这个:
You are using the unassigned variableparent
.
Try this:
void CChildDlg1::OnCheckPower24v()
{
CParentDlg *parent = (CParentDlg*)GetParent();
// Check if parent is not NULL with debug builds
ASSERT(parent);
// Check if proper class
// Requires that CParentDlg has been declared as DECLARE_DYNAMIC
// or DECLARE_DYNCREATE
ASSERT(parent->IsKindOf(RUNTIME_CLASS(CParentDlg)));
parent->GetEvent("ACTIVATE 24V");
}
请注意,上述要求必须创建子对话框,并将指针传递给父对话框(例如,传递这个
在 CParentDlg
类中调用创建
时。
注意第二个 ASSERT
调用的注释。 VC 6真的很旧(18年,13年前的最新更新),我不知道它是否适用于VC 6.
Note that the above requires that the child dialog has to be created passing a pointer to the parent dialog (e.g. by passing this
when calling Create
in the CParentDlg
class).
Note the comments for the second ASSERT
call. VC 6 is really old (18 years, last update 13 years ago) and I don't know if that works with VC 6.
通过选择正确的父级来解决这个问题。 />
因为我的孩子对话是CTabCtrl的孩子:
This is fixed by choosing the correct parent.
Since my child dialogs are child of CTabCtrl:
CTabFTE *pTab = (CTabFTE*)GetParent();
和CTabCtrl是主对话框的子代:
and the CTabCtrl is child of main dialog:
CParentDlg *parent = (CParentDlg*)GetParent()
这篇关于使用父对话框中的函数发送字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!