Re: MFC control keyhole
"Balog Pal" <[email protected]> Wed, 24 Sep 2003 19:29:28 +0100
| Newsgroups | gmane.comp.programming.keyholes |
|---|---|
| Message-ID | <003801c382cb$4d0f34c0$65bf9f81@bpnt> |
> How could I delete some or all the items from MFC combobox?
while (pmyComboBox->GetCount()) pmyComboBox->DeleteString(0);
For some weird reason a combobox doesn't have a builtin ResetContents or
DeleteAll handler, so you must do it by hand. Guess some historic reasons in
Windows 1.0 :)
> All that looks simple but at the same time resembles well known
> STL algorithms vs. cycles dilemma (Meyers "Effective STL").
Khm, hope everyone working with MFC or win API has his own set of extension
functions and call those. (peeking my mfcx_bp.h:)
inline void EmptyCombo(CComboBox& box)
{
while(CB_ERR != box.DeleteString(0))
;
}
The user side just sees EmptyCombo called everywhere (too bad we have no
interchangeable syntax in c++ to be called as box.EmptyCombo() but that's
another story...) I don't think the layout of the single implementation is
really a big problem.
> So,
> I thought how could it be good for us if the developers of MFC used STL
> containers in the controls like CComboBox so that we could use
> STL algorithms.
I generally try to keep contents of comboboxes NOT change. Fending against
user requests to filter away some items depending on other controls around.
I almost always have some container with real data, and a function that
fills the combo using that container, keeping references to the original
container items in combo itemdata.
(That certainly means transfer is not cheap nor intelligent, it deletes all,
and fills all.)
But I use algorithms and stuff just like you write. :)
The UI control itself is not really fit to that task anyway, all you have
there is a single string. Access is only by string or linear index, where
the index may be arbitrary if the combo has SORT selected. Not exactly
useful for anything but doing the UI job.
Paul