Re: CComboBox-Droplist: float values?
- From: "BobF" <rNfOrSePeAzMe@xxxxxxxxxxx>
- Date: Fri, 9 Nov 2007 12:07:06 -0600
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:rs69j31sgtil8d5pevn6gsr8et0ul0hkk3@xxxxxxxxxx
Which works fine if you believe that the only values you will have are the
ones given, and
the combo box is unsorted. I learned years ago to NEVER depend on the
index of a combo
box or list box EXCEPT to retrieve the value I want. This makes the code
robust-under-maintenance, a critical factor in what I build (code I write
will always be
maintained by unskilled labor, which means either the new hire or myself
six months later)
joe
I don't disagree. a) there really is this small number of values to choose
from and b) my approach to get a functional proof-of-concept, then optimize
based on what I've learned about the problem during the proof-of-concept
build.
On Fri, 9 Nov 2007 10:32:20 -0600, "BobF" <rNfOrSePeAzMe@xxxxxxxxxxx>
wrote:
Joseph M. Newcomer [MVP]
"BobF" <rNfOrSePeAzMe@xxxxxxxxxxx> wrote in message
news:Or7iQquIIHA.3848@xxxxxxxxxxxxxxxxxxxxxxx
"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:%23LNB7luIIHA.5328@xxxxxxxxxxxxxxxxxxxxxxx
Joseph M. Newcomer wrote:
(a) format the float value as a string
(b) add the string to the combo box
Now, if it is a *sorted* combo box, you have the classic "numeric
sort"
problem. If you
are using 'float', it is fairly easy; you create an owner-draw combo
box
without
LBS_HASSTRINGS and implement CompareItem. Store the float in the
itemData part. There is
a trick, however: you can't cast a float to an LPARAM without causing
it
to be converted
to an integer, so the trick is to do the following:
Joe:
Why not just use atof() on the strings and compare the results?
David, I've been down that road. For some reason, GetWindowTextW
returns
only the '.' of strings formatted similarly to "0.25". Obviously not
enough for atof to work with :-((
an even easier way:
.
.
.
int i = comboboxcvar.GetCurSel();
switch (i)
{
case 0: SetDuration(0.25);
break;
case 1: SetDuration(0.5);
break;
case 2: SetDuration(1.0);
break;
case 3: SetDuration(5.0);
break;
case 4: SetDuration(10.0);
.
.
.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- CComboBox-Droplist: float values?
- From: BobF
- Re: CComboBox-Droplist: float values?
- From: Joseph M . Newcomer
- Re: CComboBox-Droplist: float values?
- From: David Wilkinson
- Re: CComboBox-Droplist: float values?
- From: BobF
- Re: CComboBox-Droplist: float values?
- From: BobF
- Re: CComboBox-Droplist: float values?
- From: Joseph M . Newcomer
- CComboBox-Droplist: float values?
- Prev by Date: Re: My application "has stopped working" !!!
- Next by Date: Re: Thanks to Joseph M. Newcomer
- Previous by thread: Re: CComboBox-Droplist: float values?
- Next by thread: Re: CComboBox-Droplist: float values?
- Index(es):
Relevant Pages
|