Board index » Visual Studio » Customdraw Combobox CompareItem

Customdraw Combobox CompareItem

Visual Studio11
Hi

I have a customdrawn CComboBox derivated class and want to program my

own sort algorithm. I overwrite the ComparItem function.

The contents of the combobox will be sorted but not with my CompareItem

function but with the original sort algorithm.

My CompareItem function will never be called. I tried to handle the

WM_COMPAREITEM message but i never received one.



What do I have to do to implement my own CompareItem function ?

Or does anyone know a demo program which use a CompareItem function for

CComboboxes ?



Best regards

Joerg Tiedemann


-
 

Re:Customdraw Combobox CompareItem

Quote
I have a customdrawn CComboBox derivated class and want to program my

own sort algorithm. I overwrite the ComparItem function.

The contents of the combobox will be sorted but not with my CompareItem

function but with the original sort algorithm.

My CompareItem function will never be called. I tried to handle the

WM_COMPAREITEM message but i never received one.



Joerg,



Have you created the control with your required owner drawn style and

CBS_SORT, but without the CBS_HASSTRINGS style?



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq

-

Re:Customdraw Combobox CompareItem

Hi,

Yes the combobox has the Style CBS_SORT but it also has the Style

CBS_HASSTRINGS, because the ComboBox has Strings.

If i want to implement an owner sorted ComboBox didn't have the combobox the

style CBS_HASSTRINGS ??



Joerg



David Lowndes schrieb:



Quote
>I have a customdrawn CComboBox derivated class and want to program my

>own sort algorithm. I overwrite the ComparItem function.

>The contents of the combobox will be sorted but not with my CompareItem

>function but with the original sort algorithm.

>My CompareItem function will never be called. I tried to handle the

>WM_COMPAREITEM message but i never received one.



Joerg,



Have you created the control with your required owner drawn style and

CBS_SORT, but without the CBS_HASSTRINGS style?



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq



-

Re:Customdraw Combobox CompareItem

Quote
Yes the combobox has the Style CBS_SORT but it also has the Style

CBS_HASSTRINGS, because the ComboBox has Strings.

If i want to implement an owner sorted ComboBox didn't have the combobox the

style CBS_HASSTRINGS ??



Joerg,



If you check the documentation it says:



"If the information displayed in an owner-drawn combo box includes

text, an application can keep track of the text for each list item by

specifying the CBS_HASSTRINGS style. Combo boxes with the CBS_SORT

style are sorted based on this text. If a combo box is sorted and not

of the CBS_HASSTRINGS style, the owner must process the WM_COMPAREITEM

message.

"



In other words, WM_COMPAREITEM only occurs if you don't set

CBS_HASSTRINGS. Presumably CBS_HASSTRINGS is effectively saying to the

list - sort yourself!



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq

-

Re:Customdraw Combobox CompareItem

Hi,

Yes your are right if i disable CBS_HASSTRINGS my own CompareItem Function will

be called.

But is there no way to use the CBS_HASSTRINGS style in combination with an own

CompareItem function ?

Joerg



David Lowndes schrieb:



Quote
>Yes the combobox has the Style CBS_SORT but it also has the Style

>CBS_HASSTRINGS, because the ComboBox has Strings.

>If i want to implement an owner sorted ComboBox didn't have the combobox the

>style CBS_HASSTRINGS ??



Joerg,



If you check the documentation it says:



"If the information displayed in an owner-drawn combo box includes

text, an application can keep track of the text for each list item by

specifying the CBS_HASSTRINGS style. Combo boxes with the CBS_SORT

style are sorted based on this text. If a combo box is sorted and not

of the CBS_HASSTRINGS style, the owner must process the WM_COMPAREITEM

message.

"



In other words, WM_COMPAREITEM only occurs if you don't set

CBS_HASSTRINGS. Presumably CBS_HASSTRINGS is effectively saying to the

list - sort yourself!



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq



-

Re:Customdraw Combobox CompareItem

Quote
Yes your are right if i disable CBS_HASSTRINGS my own CompareItem Function will

be called.



Good.



Quote
But is there no way to use the CBS_HASSTRINGS style in combination with an own

CompareItem function ?



I guess not. The documentation doesn't say so anyhow.



Dave

--

MVP VC++ FAQ: www.mvps.org/vcfaq">www.mvps.org/vcfaq

-