我正在尝试初始化一个CDialog框,其中包含一个CListBox。我想通过在DoModal上调用CDialogBox来实现这一点。但是问题是,当我调用DoModal时,对话框会打开,但是CListBox是空的。(它的项已经初始化)当我调用ShowWindow(SW_SHOW)时,对话框也会出现,并且CListBox包含我插入到其中的项。但是,我不想使用此方法,因为它不会暂停程序的执行。(DoModal暂停程序执行,直到窗口关闭)
因此,我的问题是:如何使用打开对话框,并让CListBox显示其内容?非常感谢。
初始化CDialog子类,并调用start (这将打开对话框)
loadNewWorld = new LoadNewWorld(this);
loadNewWorld->Create(IDD_LOAD_NEW_WORLD , this);
loadNewWorld->Start();LoadNewWorld类:
//Constructor header
LoadNewWorld::LoadNewWorld(CWnd* pParent /*=NULL*/) : CDialog(LoadNewWorld::IDD, pParent)
//This shows the dialog box, but does NOT show the items in CListBox
void LoadNewWorld::Start ()
{
populateList();
DoModal();
}
//This shows the dialog box AND shows the populated CListBox. However, don't want to do this way
void LoadNewWorld::Start ()
{
populateList();
ShowWindow(SW_SHOW);
}发布于 2014-11-14 09:05:16
在对话框启动并创建时填充列表视图。
无法在未创建对话框时填充列表框。最好的地方是OnInitDialog。您的问题是,您希望在创建列表框之前(在调用DoModal之前)填充它。
正如注释中已经告诉您的:您不能混合DoModal和Create。
https://stackoverflow.com/questions/26919136
复制相似问题