Why is my collector drawn by the owner shown empty?

I am subclassing the WTL combobox, and I am the owner-drawing of combobox elements. The control has attributes CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWVARIABLE CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWVARIABLE CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWVARIABLE , and I use the COwnerDraw mixed class class to implement DrawItem () and MeasureItem (). When the drop-down list is omitted, the elements are drawn correctly. However, with the drop-down list, the combobox control is empty and the element is not drawn. What am I doing wrong?

The WTL class is as follows:

 class CMyComboBox : public CWindowImpl<CMyComboBox, CComboBox>, public COwnerDraw<CMyComboBox> { public: BEGIN_MSG_MAP_EX(CMyComboBox) CHAIN_MSG_MAP(COwnerDraw<CMyComboBox>) CHAIN_MSG_MAP_ALT(COwnerDraw<CMyComboBox>, 1) END_MSG_MAP() void DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDCHandle dc = lpDIS->hDC; dc.FillSolidRect(&lpDIS->rcItem, lpDIS->itemID == 0 ? RGB(255,0,0) : RGB(0,255,0)); } void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { lpMeasureItemStruct->itemWidth = 12; lpMeasureItemStruct->itemHeight = 12; } }; 

The class is used in the dialog box and is subclassed as follows:

  m_cbMy.SubclassWindow(GetDlgItem(IDC_COMBO1)); m_cbMy.AddString(_T("Item 1")); m_cbMy.AddString(_T("Item 2")); 

Changing control attributes to CBS_OWNERDRAWFIXED does not change anything.


Edit: Thanks to the help of najmeddine, I realized that I have to process WM_PAINT to draw the actual combobox, not just the items in the drop-down list. Unfortunately, now I also have to use the combobox control myself. Is there a way for GDI to draw a border and lower the arrow, so that I only need to draw the "insides" of the control?

+4
source share
3 answers

To draw a combobox control, you must use the theme API in your WM_PAINT handler (in XP + you won’t tell which versions of Windows you need to support.) In particular, use DrawThemeBackground and pass one of the CB_ values for iPartId .

You will also need to use buffered drawing APIs to handle transitions in Vista, which can complicate your paint processor β€” these are other problems with painting when custom painting the combobox control is explained here in a lot of detail. I would suggest using this forum as the main link that implements this.

+6
source

In DrawItem, you fill the rectangle with color. But where is DrawText or something like that?

Custom DrawItem example .

0
source

To draw a comboBox control (not a list), you also need to process the WM_PAINT message and make your picture there. The DrawItem event DrawItem creates a list of drop-down lists and items.

0
source

All Articles