I want to owner draw a CComboBoxEx m_ctlCombo with text and images.
I create the image list and create COMBOBOXEXITEM and insert them into m_ctlCombo. It's all good.
My question is how do I get the COMBOBOXEXITEM items in my ownerdrawn function from which I can extract the text "test" to draw.Code:// Add strings to the combo box. for (int idx = 0; idx < 3; idx++) { // Each item has text, an lParam with extra data, and an image. cbI.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE; cbI.pszText = _T("test"); // this will be different for each item cbI.cchTextMax = sizeof(_T("test")); cbI.iItem = idx; // Add the item to the end of the list. cbI.iImage = idx; // Image to display. cbI.iSelectedImage = idx; cbI.iOverlay = 2; cbI.iIndent = 0; // Add the item to the combo box drop-down list. int test = m_ctlCombo.InsertItem(&cbI); // works! }
I'm using WTL but I think it does not matter. TIACode:// COwnerDraw LRESULT DrawItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT) lParam; if( lpDrawItemStruct->itemID == -1 ) return 0; CDCHandle dc = lpDrawItemStruct->hDC; const int nIndex = lpDrawItemStruct->itemID; COMBOBOXEXITEM cbei; GetItem(&cbei); // this Does Not work to get items with text LPCTSTR lpszText = cbei.pszText; // How? RECT rc = lpDrawItemStruct->rcItem; // this works to get rect CImageList pImageList = GetImageList(); // this works to get image list // ... // code to draw text and images // ... }




Reply With Quote