如何在MFC的ComboBox中添加项目? [英] How to add items to ComboBox in MFC?

查看:358
本文介绍了如何在MFC的ComboBox中添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于对话框的MFC应用程序

在那里我添加了一个组合框

我使用向导作为combobox1将变量分配给了combobox

使用添加处理程序向导,我将OnCreate Routine添加到对话框文件

当我在该例程中将项目添加到combobox时,它可以成功编译,但在运行时会产生问题,提示"Debug Assertion Failed",并指向某个内部库.
我使用了代码

i created a dialog based MFC app

there i added a combobox

i assigned a variable to combobox using wizard as combobox1

using add handler wizard, i added OnCreate Routine to the dialogbox file

when i add items to combobox in that routine, it compiles successfully but its creating problem at runtime, saying "Debug Assertion Failed" and pointing to some internal library..

i used the code

int CSampleMFCDlgDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CDialogEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    combobox1.AddString(L"Hello");
    combobox1.AddString(L"World");

    return 0;
}







whats wrong with it??

推荐答案

我相信您在尚未创建组合框控件的过程中添加项目的时间过早.与其在OnCreate()中进行操作,不如在OnInitDialog()中添加项目.


Soren Madsen
I believe you are adding the items too early in the process where the combo box control has not been created yet. Instead of doing it in OnCreate(), add the items in OnInitDialog().


Soren Madsen


这篇关于如何在MFC的ComboBox中添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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