积极答复者
对话框初始化

问题
-
在OnInitDialog()中出示化
BOOL CSetStyleDlg::OnInitDialog()
{CString str;
for(int i=0;i<20;i++)
{
str.Format(_T("item string %d"),i);
m_LineStyleCmd->AddString(str);
}
CDialog::OnInitDialog();}
然后调试时出现,For information on how your progarm can cause an assertion failure.see the visul C++ on documentation on asserts.
如果忽略,触发断点
断点处代码为_AFXWIN_INLINE int CComboBox::AddString(LPCTSTR lpszString)
{ ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString); }这个问题困扰了好长时间,谁能帮我解决,万分感谢!
答案
-
云轩阁,
您好!这个问题很可能是您的combobox未生成就被调用了,比如你一个对话话,上面有下拉框,你还没DoModel或还没有Create之前就对下拉框操作了。请您在domodel之后进行这些操作试试。
另外,您还可以尝试下改变了给combobox赋值的方式。
把m_LineStyleCmd->AddString(str)改成GetDlgItem(控件ID)->SetWindowText(str);
如果您的问题解决了,请把有用的回答标记为答案!
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 云轩阁 2011年5月2日 14:22
全部回复
-
BOOL CSetStyleDlg::OnInitDialog()
{
CDialog::OnInitDialog(); // 放到这里
CString str;
for(int i=0;i<20;i++)
{
str.Format(_T("item string %d"),i);
m_LineStyleCmd->AddString(str); // 另外您的m_ListStyleCmd是CComboBox*吗?您怎么关联您的窗口对象的?动态创建的代码贴出来看看
}
}
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development. -
云轩阁,
您好!这个问题很可能是您的combobox未生成就被调用了,比如你一个对话话,上面有下拉框,你还没DoModel或还没有Create之前就对下拉框操作了。请您在domodel之后进行这些操作试试。
另外,您还可以尝试下改变了给combobox赋值的方式。
把m_LineStyleCmd->AddString(str)改成GetDlgItem(控件ID)->SetWindowText(str);
如果您的问题解决了,请把有用的回答标记为答案!
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 云轩阁 2011年5月2日 14:22
-
云轩阁,
您好!一下链接是讲combobox的,并有源码下载,您可以下载它们提供的源码学习。
讲解CComboBox控件的基本运用,适合入门级的人学习。http://www.codeproject.com/KB/combobox/CustomComboBox.aspx
讲解带有用户自定义的popup控件的Combobox控件:http://www.codeproject.com/KB/combobox/CustomComboBox.aspx
更多的关于combobox的代码请看:
http://www.codeproject.com/KB/combobox/
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.