1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
MComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
int nItem=GetCurSel();
CString sText(_T(""));
if(lpDrawItemStruct->itemID!=-1)
nItem=lpDrawItemStruct->itemID;
if(nItem!=-1)
GetLBText(nItem,sText);
BOOL bHighlight=(lpDrawItemStruct->itemState & (ODS_FOCUS | ODS_SELECTED));
BOOL bFocus=(lpDrawItemStruct->itemState & ODS_FOCUS);
CRect rect=lpDrawItemStruct->rcItem;
// fill background
::FillRect(lpDrawItemStruct->hDC,rect,
::GetSysColorBrush(!IsWindowEnabled() ? COLOR_3DFACE :
(bHighlight ? COLOR_HIGHLIGHT : COLOR_WINDOW)));
if(!sText.IsEmpty())
{
if(bFocus)
::DrawFocusRect(lpDrawItemStruct->hDC,rect);
// select font
::SelectObject(lpDrawItemStruct->hDC,(HFONT)SendMessage(WM_GETFONT,0,0));
// set text attributes
::SetBkMode(lpDrawItemStruct->hDC,TRANSPARENT);
if(bHighlight)
::SetTextColor(lpDrawItemStruct->hDC,
::GetSysColor(COLOR_HIGHLIGHTTEXT));
else if(IsWindowEnabled())
::SetTextColor(lpDrawItemStruct->hDC,
::GetSysColor(COLOR_WINDOWTEXT));
else
::SetTextColor(lpDrawItemStruct->hDC,
::GetSysColor(COLOR_3DSHADOW));
rect.DeflateRect(1,1);
// draw the text
::DrawText(lpDrawItemStruct->hDC,sText,sText.GetLength(),rect,
DT_LEFT|DT_VCENTER|DT_SINGLELINE);
// mettre DT_WORDBREAK à la place de DT_VCENTER|DT_SINGLELINE
}
}
// après il faut reprendre la main sur les notifications :
BOOL MComboBox::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
// TODO: Add your specialized code here and/or call the base class
switch (message)
{
case WM_DRAWITEM:
DrawItem((LPDRAWITEMSTRUCT)lParam);
break;
default:return CComboBox::OnChildNotify(message, wParam, lParam, pLResult);
}
return TRUE;
} |
Partager