Multiple CComboBox share the same data

I have an MFC dialog with 32 CComboBoxes where everyone has the same data in the list. This will take a while, and it looks like part of the delay is the time I need to spend using InsertString () to add all the data to 32 controls. How can I subclass CComboBox so that 32 instances use the same data?

0


source to share


4 answers


Disable window redrawing when filling a combo. eg:.

m_wndCombo.SetRedraw(FALSE);
// Fill combo here
...
m_wndCombo.SetRedraw(TRUE);
m_wndCombo.Invalidate();

      



This can help.

+1


source


The first thing I'll try is to call "InitStorage" to pre-allocate internal storage for strings. From MSDN:

// Initialize the storage of the combo box to be 256 strings with // about 10 characters per string, performance improvement.



int n = pmyComboBox-> InitStorage (256, 10);

0


source


In addition to what has already been said, you can also turn off sorting in your combo box and pre-configure the data before inserting it.

0


source


The owner you drew will go in one direction at your request - you'll be writing a fair piece of code, but you won't have to add data to all of them. " CComboBox :: DrawItem "

Support.microsoft has this article on Subclassing Combo Field, which may also be of interest " How to Subclass CListBox and Cedit Inside CComboBox "

Indeed, one has to ask if it's worth the effort and a lot of it depends on things like

  • number of entries in the list
  • number of impressions in the dialog
  • volatility of combo content
  • Optoisation elsewhere
    • do not draw until the screen is complete
    • will create a dialogue only once and show it again.
    • using one combination but showing it in different places at different times
0


source







All Articles