Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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??
Posted
Updated 2-Jun-12 18:19pm
v2
Comments
Harmanjeet Singh 3-Jun-12 0:46am    
i checked, there is no Windows Message WM_INITDIALOG or WM_INIT_DIALOG or something related...??

1 solution

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
 
Share this answer
 
Comments
Harmanjeet Singh 3-Jun-12 0:40am    
& what will be the Windows Message for OnInitDialog??
WM_......?
SoMad 3-Jun-12 0:51am    
If you are using the MFC Class Wizard, go to the "Virtual Functions" tab and select OnInitDialog() in the list.

Soren Madsen
Harmanjeet Singh 3-Jun-12 0:57am    
hey! :D it worked.. thanx a lot..
:)
SoMad 3-Jun-12 1:02am    
You are welcome. I know it is a bit confusing that this function is under a different tab while having a name that suggests you would add it under the "Messages" tab. It has always been like that, so I forgot to mention it.

Soren Madsen

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900