我正在编写一个 DrawItem 覆盖方法来修改应用程序,因此 ComboBox DropDowns 中的文本都使用 pDC->DrawText 函数将 DT_SINGLELINE|DT_VCENTER 解析为最终参数居中。我目前遇到的问题是我可以在 DropDown 中重复第一个值,但我想要在 DropDown 中显示的所有值的列表。
我不确定这里是否存在与应用程序中的其他控件一样的基本缺陷,例如在调用 DrawItem 覆盖时似乎填充了 ListCtr lpDrawItemStruct->itemData。但是对于 ComboBox lpDrawItemStruct->itemData 的情况,它显示为空。
请问有人可以帮忙吗?以下是到目前为止的代码。
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 );
}