Re: OwnerDrawn CComboBoxEx
Quote:
Originally Posted by
cbpetro
Code:
// 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
}
Why don't you use DRAWITEMSTRUCT itemData to get the item text?
Have a look at the owner draw comobox example.
Re: OwnerDrawn CComboBoxEx
I'm working with the CComboBoxEx class which uses strings and images stored in COMBOBOXEXITEM items. The CComboBox class which you referenced just uses strings.
I want to be able to access the COMBOBOXEXITEMS in my owner draw function to get the images and strings which I inserted into my owner drawn control using ...
Code:
m_ctlCombo.InsertItem(&cbI)
Re: OwnerDrawn CComboBoxEx
Again:
1. Did you try to use DRAWITEMSTRUCT itemData to get the item text?
2. Did you look at the owner draw combobox example from MSDN?
Re: OwnerDrawn CComboBoxEx
Yes, I checked out the MSDN example and tried...
Code:
CDCHandle dc = lpDrawItemStruct->hDC;
// COMBOBOXEXITEM cbei = (COMBOBOXEXITEM) lpDrawItemStruct->itemData; // Won't compile
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData; // does't access strings - gives junk
I don't think that's the solution. I scoured the net for a solution/example and haven't found out how to do this. Thanks for your ideas.
Re: OwnerDrawn CComboBoxEx
I figured it out.
You have to 'prep' COMBOBOXEXITEM prior to calling GetITem.
Code:
const int nIndex = lpDrawItemStruct->itemID;
TCHAR tstr[20];
COMBOBOXEXITEM cbei;
ZeroMemory( &cbei, sizeof( COMBOBOXEXITEM ) );
cbei.mask = CBEIF_TEXT;
cbei.iItem = nIndex;
cbei.pszText = tstr;
cbei.cchTextMax = 20;
GetItem(&cbei); // now it works !
// tstr is the assigned string