I am writing a DrawItem override method to modify an application so the text in the ComboBox DropDowns are all centred using the pDC->DrawText function parsing DT_SINGLELINE|DT_VCENTER as the final parameter. The issue I'm having at the moment is I can get the first value repeated in the DropDown but I want a list of all the values displayed in the DropDown.
I'm not certain if there is a fundamental flaw here as in other controls in the application e.g. a ListCtr lpDrawItemStruct->itemData seems to be populated when the DrawItem override is called. However for the case of the ComboBox lpDrawItemStruct->itemData appears empty.
Please can anyone help with this? Below is the code so far.
void CFCDropDown::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC) ;
int nSavedDC = pDC->SaveDC();
//I can't use the following because at this stage lpDrawItemStruct->itemData doesn't contain anything
//LPCTSTR lpszText = (LPCTSTR)lpDrawItemStruct->itemData ;
//I do however have access to a member variable that contains the list of items I want in the drop down
//m_strListEntry contains a CString of format "ONE;TWO;THREE;FOUR;FIVE;SIX"
CString strFieldValue = m_strListEntry ;
int noOfItems = GetCount();
CString item;
int iStartPos = 0;
int iFirstDelimiter = 0;
iFirstDelimiter = m_strListEntry.Find(LISTDELIMITER,iStartPos);
int i = iFirstDelimiter + 1;
int iStrLen = strFieldValue.GetLength();
int iNewLen = iStrLen - ++iFirstDelimiter;
item = strFieldValue.Left(i -1) ;
LPCTSTR lpszText = (LPCTSTR)item ;
//At the moment I'm getting "ONE" repeated 6 times. I want a list of all the values displayed in the DropDown.
pDC->DrawText(lpszText, strlen(lpszText), &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER) ;
pDC->RestoreDC( nSavedDC );
}
GetLBText(lpDIS->itemID,strItem);
. Otherwise populate the ComboBox wheneverm_strListEntry
is set. – Anonymous Coward