MFC dialogs with CComboBoxes
So the problem is, how to insert strings to a CComboBox (dropdown list) in an MFC dialog created with the editor. (Visual C++ 5.0, no service packs)
I've got the code below where I would need the dialog box. The m_terrainCombo is mapped through ClassWizard to the combo box as a control (CComboBox).
...
CLandDialog landDlg;
// CComboBox* terrainCombo = (CComboBox*) landDlg.GetDlgItem(1010); // try to get the combo box a different way (gives an assertion error)
// landDlg.m_terrainControl.InsertString(0, "Hills"); // as gives this
// .. access the other controls.. (works fine)
landDlg.DoModal();
...
No matter which of the commented lines I use, it throws an assertion error and refuses to add anything. (The assertion usually is something about m_hWnd, but I don't actually get it, what's it trying to say. I tried to give the dlg a handle to my main wnd, but it didn't change anything.) I've tried to read the docs and the books I have, and according to everything, those both lines should be just ok, so if someone knows what I'm missing here, please reply.
--
.. I tried to fix it now again today and I found out that the m_hWnd of the dialog box is always NULL, why is that? and is that normal? And because of that, it always gives an assertion error when trying to do something with the window. How to get around this? Any ideas?
Edited by - Corben on 7/20/00 3:39:34 AM
Well, I''m not totally sure this is what you''re doing, but from what it looks like, you are attempting to put stuff in the combo box before the combo box technically exists. Your other control stuff probably works because you are probably setting the variables relating to those windows rather than trying to access the windows themselves. This would be why your dialog window handle is NULL... until you DoModal you don''t actually have a window. (and yes, I know this because I''ve made this mistake... *sheepish look).
So what you need to do is make an array or linked list in your dialog box class which will hold the information you want to put into the combo box until the box is actually initialized, and for dialogs I believe populating from OnInit will work fine, don''t quote me on that tho because I don''t have any of that source with me at the moment.
Yell if you have any more problems.
-fel
So what you need to do is make an array or linked list in your dialog box class which will hold the information you want to put into the combo box until the box is actually initialized, and for dialogs I believe populating from OnInit will work fine, don''t quote me on that tho because I don''t have any of that source with me at the moment.
Yell if you have any more problems.
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Ah, of course.. that was just the case. The thing was that I thought I had thought of that before, becouse I had tried the lines _after_ the DoModal() too.. Yep, should''ve thought of it for a second. Fortunately now with the CStringList it took only a three lines of code to add the same functionality back.
Thanks!
Thanks!
I''m sure you already know this, but just in case you don''t:
The easiest way to put text in a combobox, is to modify the data tab under the combobox properties in the resource view. Just add them one after another here.
Of course they are not dynamic, but it sounds like yours may be fairly fixed. Plus you can add items with code.
I''m not sure if ver.5 has this in it''s resource editor.
The easiest way to put text in a combobox, is to modify the data tab under the combobox properties in the resource view. Just add them one after another here.
Of course they are not dynamic, but it sounds like yours may be fairly fixed. Plus you can add items with code.
I''m not sure if ver.5 has this in it''s resource editor.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement