儿童对话框 - setWindowTexta或sendmessagea崩溃程序-MFC
Child Dialog - SetWindowTextA or SendMessageA crashes program - MFC
错误:afxwin2.inl行165
我的应用程序是一个带有一些编辑框的对话框。单击按钮以评估输入的信息后,我想打开一个子对话框以显示结果。我尝试过以下超载Domodal():
//in the child dialog
//.h
CResultsDlg::CResultsDlg(CParentDlg *parent);
virtual INT_PTR DoModal(float bmi);
//.cpp
CResultsDlg::CResultsDlg(CParentDlg *parent) : CDialogEx(CResultsDlg::IDD), _parent(parent)
{ //initializations }
INT_PTR CResultsDlg::DoModal(float bmi)
{
m_sBMI.Format("%f", bmi);
m_hBMI.SetWindowTextA(m_sBMI); //crashes !!!!!!!!!!
m_hBMI.SendMessageA(WM_SETTEXT, 0, (LPARAM)"15.11"); //crashes !!!!!!!!
// OnInitDialog(); //because this wasn't getting called at all
return CDialogEx::DoModal();
}
BOOL CResultsDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// __super::OnInitDialog(); //no difference...
m_hBMI.SetWindowTextA("10.3"); //crashes !!!
return true; // return TRUE unless you set the focus to a control
}
//in the parent dialog
//.cpp
void CParentDlg::OnBnClickedCalculate()
{
CResultsDlg childResultsDlg = this;
childResultsDlg.DoModal(15.7);
}
m_hbmi是静态文本控件的手柄。我测试了一个编辑框,但仍然崩溃了。我了解这可能与尚未创建的控件有关,但我尝试了各种各样的方式。
使用断点,我确认除非我将其放在过载的domodal函数中,否则根本不会被调用。setWindowText/sendmessage仍然在OnInitDialog中崩溃,并具有相同的断言错误。
如果我删除了所有setWindowText/sendmessage,则"子"窗口确实会像应有的那样出现模式,但是"结果"静态文本控件与我在对话框编辑器属性窗格中设置的文本相同。
谢谢!!!!!
*更多详细信息* ----------------------
void CResultsDlg::DoDataExchange(CDataExchange* pDX) // DDX/DDV support
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_BMI, m_fBMI);
DDV_MinMaxFloat(pDX, m_fBMI, 0, 100);
DDX_Control(pDX, IDC_BMI, m_hBMI);
}
启动对话框时的通常序列是:
- 您称CDIALOG :: DOMODAL。
- 创建对话框窗口。
- 创建对话框的孩子控制。
- oninitdialog被称为。
- cdialog :: oninitdialog调用dodataexchange。
- 您在您的dodataexchange方法中有一个ddx_control调用,可以将子控制映射到成员变量。
请注意,成员变量仅在该序列的末尾初始化。您以前尝试使用它们,因此您会崩溃。
将初始化所需的值存储在成员变量中,并在Dodataexchange中照顾它。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- 程序崩溃并显示"std::out_of_range"错误
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 为什么我的多线程作业队列崩溃
- ExtractIconEx:可以工作,但偶尔会崩溃
- 为什么引用传递会导致此崩溃(C++)
- 试图创建流或fopen时程序崩溃
- 类对象数组的问题会导致崩溃
- 排序时无法执行交换操作.我做的时候它会崩溃.为什么
- 为什么要增加导致崩溃的指针
- 在虚幻引擎中删除NXOpen对象时崩溃
- 为什么它只打印双链接列表的第一个值,而我的程序却崩溃了
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- Visual Studio在尝试读取resource.txt文件时崩溃
- 儿童对话框 - setWindowTexta或sendmessagea崩溃程序-MFC