Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow performance of AddString in MFC [duplicate]

I've got a dialog with several largeish combo boxes in it (maybe several hundred items apiece). There's a noticeable delay at construction while these are populated (confirmed that it's them by profiling).

My initial thought was that sorting was killing it's performance, but disabling sort and using InsertString instead doesn't seem to make things much better. I hadn't thought that it seemed like an excessive number of items - is there something else I should be doing or considering here?

The MFC calls are trivial wrappers to Win32 message calls so I don't think there's any significant overhead there.

DUPLICATE How to load a large array of strings in to an MFC combobox control fast as possible?

like image 924
Peter Avatar asked Dec 23 '22 14:12

Peter


1 Answers

You should be using CWnd::SetRedraw around your adds, to prevent the control updating all its internal state after each add.

If you're not already doing it, then do this:

combo.SetRedraw(FALSE);

...  All the adds

combo.SetRedraw(TRUE);
combo.Invalidate();

You should also consider using the CComboBox::InitStorage function, which preallocates memory for the combo-box.

like image 180
Will Dean Avatar answered Dec 28 '22 10:12

Will Dean