如何在MFC的子对话框中初始化控件 [英] How to initiliase the controls in a child dialog in MFC

查看:127
本文介绍了如何在MFC的子对话框中初始化控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对话框和一个按钮.然后,当我单击该按钮时,应该会弹出一个子对话框.
我在主对话框中使用一些数据来初始化子对话框的标题及其列表框,如下所示.

I''ve got a dialog and a button on that. And once I click the button, a child dialog should pop up.
I use some data inside the main dialog to initialise the child dialog''s caption and its list box like the following.

CChildDlg dlg;
dlg.SetWindowTextW(wszTitle);
dlg.m_ctrlLB.AddString(wszLBEntry);  // m_ctrlLB is a variable of type CListBox
dlg.DoModal();


但这只会产生运行时错误.有人可以帮忙吗?
在此先谢谢您.


But this just gives a runtime error. Anyone could help?
Thanks in advance.

推荐答案

您必须覆盖 OnInitDialog () [^ ]对话框类并在那里进行更新.

Soren Madsen
You have to override OnInitDialog()[^] in your dialog class and do those updates there.

Soren Madsen


好吧,您不应该直接访问对话框控件,而是尝试初始化一些公共成员(使用成员变量或访问方法),然后在对话框中更新控件在适当的时候.如果是CDialog,则为OnInitDialog().

将来,发布断言告诉您什么以及代码中的哪一行触发断言.通常,如果您仔细查看断言,它将确切告诉您触发该断言的内容.
Well, you shouldn''t be accessing the dialogs controls directly, rather, try initialiazing some public members (either using member variables or access methods) then update the controls within the dialog at the proper time. In the case of a CDialog, that would be OnInitDialog().

In the future, post what the assertion is telling you and what line within your code is triggering the assertion. Usually if you look closely at the assertion, it will tell you exactly what you need to know about what triggered it.


这篇关于如何在MFC的子对话框中初始化控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆