I have a MFC dialog with 32 CComboBoxes on it that all have the same data in the listbox. Its taking a while to come up, and it looks like part of the delay is the time I need to spend using InsertString() to add all the data to the 32 controls. How can I subclass CComboBox so that the 32 instances share the same data?
+1
A:
Turn off window redrawing when filling the combos. e.g.:
m_wndCombo.SetRedraw(FALSE);
// Fill combo here
...
m_wndCombo.SetRedraw(TRUE);
m_wndCombo.Invalidate();
This might help.
Rob
2008-12-04 22:47:47
I think you will need to make sure you call Invalidate after doing this.
grepsedawk
2008-12-04 22:50:42
Not if calling from WM_INITDIALOG IIRC, but well spotted. :)
Rob
2008-12-04 22:52:24
fixing the symptom but not answering the question.
baash05
2008-12-05 00:27:18
A:
grepsedawk
2008-12-04 22:48:03
A:
In addition to what has already been said, you might also turn off sorting in your combo box and presort the data before you insert it.
Mark Ransom
2008-12-04 23:16:29
A:
One way along the lines of your request would be to go owner drawn - you will be writing a fair chunk of code, but you won't have to add the data to all of them. "CComboBox::DrawItem"
Support.microsoft have this article on subclassing a Combo box which might also be of interest "How to subclass CListBox and Cedit inside of CComboBox"
Really one has to ask if it is worth the effort, and alot of that depends things like
- number of entries in the list
- number of times the dialog will show
- variability of the combo content
- optomising elsewhere
- not drawing until the screen is complete
- only building the dialog once and re showing it.
- using the one combo but showing it in different locations at different times
Greg Domjan
2008-12-05 03:37:53