Aracılığıyla paylaş


CComboBox::DrawItem

Görsel yönü, sahibi tarafından çizilen birleşik giriş kutusunu değişiklikleri zaman çerçevesi tarafından çağrıldı.

virtual void DrawItem(
   LPDRAWITEMSTRUCT lpDrawItemStruct 
);

Parametreler

  • lpDrawItemStruct
    Bir işaretçi bir DRAWITEMSTRUCT gerekli çizim türü hakkında bilgi içeren yapısı.

Notlar

İtemAction üyesi DRAWITEMSTRUCT gerçekleştirilmesi gereken çizim eyleminin yapısını tanımlar.Bkz: CWnd::OnDrawItem bu yapının bir açıklaması.

Varsayılan olarak, bu üye işlev hiçbir şey yapmaz.Sahibi tarafından çizilen çizim uygulamak için bu üye işlevi geçersiz kılma CComboBox nesnesi.Bu üye işlevi sona erdirmeden önce uygulamanın tüm grafik aygıt arabirimi (GDI) nesneleri ekran bağlam içinde sağlanan için seçilen kurtarmalısınız lpDrawItemStruct.

Örnek

// CMyComboBox is my owner-drawn combo box derived from CComboBox. This 
// example draws an item's text centered vertically and horizontally. The 
// combo box control was created with the following code:
//   pmyComboBox->Create(
//      WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL|
//      CBS_SORT|CBS_OWNERDRAWVARIABLE,
//      myRect, pParentWnd, 1);
//
void CMyComboBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
   ASSERT(lpDrawItemStruct->CtlType == ODT_COMBOBOX);
   LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
   ASSERT(lpszText != NULL);
   CDC dc;

   dc.Attach(lpDrawItemStruct->hDC);

   // Save these value to restore them when done drawing.
   COLORREF crOldTextColor = dc.GetTextColor();
   COLORREF crOldBkColor = dc.GetBkColor();

   // If this item is selected, set the background color 
   // and the text color to appropriate values. Erase
   // the rect by filling it with the background color.
   if ((lpDrawItemStruct->itemAction & ODA_SELECT) &&
      (lpDrawItemStruct->itemState  & ODS_SELECTED))
   {
      dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
      dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));
   }
   else
   {
      dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
   }

   // Draw the text.
   dc.DrawText(
      lpszText,
      (int)_tcslen(lpszText),
      &lpDrawItemStruct->rcItem,
      DT_CENTER|DT_SINGLELINE|DT_VCENTER);

   // Reset the background color and the text color back to their
   // original values.
   dc.SetTextColor(crOldTextColor);
   dc.SetBkColor(crOldBkColor);

   dc.Detach();
}

Gereksinimler

Başlık: afxwin.h

Ayrıca bkz.

Başvuru

CComboBox sınıfı

Hiyerarşi grafik

CComboBox::CompareItem

WM_DRAWITEM

CComboBox::MeasureItem

CComboBox::DeleteItem