本文整理汇总了C++中CDC::DrawFocusRect方法的典型用法代码示例。如果您正苦于以下问题:C++ CDC::DrawFocusRect方法的具体用法?C++ CDC::DrawFocusRect怎么用?C++ CDC::DrawFocusRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CDC
的用法示例。
在下文中一共展示了CDC::DrawFocusRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawItem
void CComboColorPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
CBrush brushBlack;
brushBlack.CreateStockObject(BLACK_BRUSH);
if (!dc.Attach(lpDrawItemStruct->hDC))
return;
COLORREF rgbTextColor = dc.GetTextColor();
COLORREF rgbBkColor = dc.GetBkColor();
if (lpDrawItemStruct->itemAction & ODA_FOCUS)
{
dc.DrawFocusRect(&lpDrawItemStruct->rcItem);
}
else if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
{
if (lpDrawItemStruct->itemState & ODS_FOCUS)
dc.DrawFocusRect(&lpDrawItemStruct->rcItem);
else
dc.ExtTextOut(0, 0, ETO_OPAQUE, &lpDrawItemStruct->rcItem, _T(""), 0, NULL);
}
if (0 <= (int)lpDrawItemStruct->itemID) // Any item selected?
{
::InflateRect(&lpDrawItemStruct->rcItem, -2, -2);
if( (COLORREF)lpDrawItemStruct->itemData == 0xFFFFFFFF )
{
CSize textSize = dc.GetTextExtent( _T("default") );
dc.FillSolidRect( &lpDrawItemStruct->rcItem, RGB( 0xFF, 0xFF, 0xFF ) );
dc.FrameRect( &lpDrawItemStruct->rcItem, &brushBlack );
dc.SetTextColor( RGB( 0x00, 0x00, 0x00 ) );
dc.SetBkColor( RGB( 0xFF, 0xFF, 0xFF ) );
dc.SetTextAlign( TA_CENTER | TA_TOP | TA_NOUPDATECP );
dc.TextOut(
lpDrawItemStruct->rcItem.left + (lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left) / 2,
lpDrawItemStruct->rcItem.top +
((lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top) / 2) -
(textSize.cy / 2),
_T("default") );
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, (COLORREF)lpDrawItemStruct->itemData);
dc.FrameRect(&lpDrawItemStruct->rcItem, &brushBlack);
}
}
// Restore the DC state
dc.SetTextColor(rgbTextColor);
dc.SetBkColor(rgbBkColor);
dc.Detach();
}
示例2: OnDrawItem
void CAboutDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDIS)
{
CDC *pDC = CDC::FromHandle(lpDIS->hDC);
switch (lpDIS->CtlType)
{
case ODT_BUTTON:
{
TCHAR buff[128];
::GetWindowText(lpDIS->hwndItem, buff, 128);
pDC->FillSolidRect(&lpDIS->rcItem, RGB(0, 0, 0)); //Button color
pDC->DrawEdge(&lpDIS->rcItem, EDGE_RAISED, BF_RECT);
pDC->SetTextColor(RGB(255, 255, 255));
pDC->DrawText(buff, &lpDIS->rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
if (lpDIS->itemState & ODS_FOCUS) // If the button has focus
{
if (lpDIS->itemState & ODS_SELECTED)
pDC->DrawEdge(&lpDIS->rcItem, EDGE_SUNKEN, BF_RECT); // Draw a sunken face
lpDIS->rcItem.top += 4; lpDIS->rcItem.left += 4;
lpDIS->rcItem.right -= 4; lpDIS->rcItem.bottom -= 4;
pDC->DrawFocusRect(&lpDIS->rcItem);
}
break;
}
}
}
示例3: dc
int
CPhylogenView::ClearSelected(int *Selection)
{
CGenedocDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
*Selection = 0;
CClientDC dc(this);
OnPrepareDC(&dc);
POSITION Pos;
Pos = pDoc->m_pPGBase->m_PhyloList.GetHeadPosition();
while ( Pos != NULL ) {
CPhyloGenBase * pPGB = (CPhyloGenBase *)pDoc->m_pPGBase->m_PhyloList.GetNext(Pos);
if ( pPGB->m_Selected == 1 ) {
CDC* pDC = GetDC();
pPGB->m_Selected = 0;
CRect tRect = pPGB->m_ClientRect;
dc.LPtoDP( &tRect );
pDC->DrawFocusRect( tRect );
ReleaseDC( pDC );
return 1;
}
(*Selection)++;
}
return 0;
}
示例4: DrawItem
void CColourPicker::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
ASSERT(lpDrawItemStruct);
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;
CString m_strText;
CSize Margins(::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE));
// Draw arrow
if (m_bActive) state |= ODS_SELECTED;
pDC->DrawFrameControl(&m_ArrowRect, DFC_SCROLL, DFCS_SCROLLDOWN |
((state & ODS_SELECTED) ? DFCS_PUSHED : 0) |
((state & ODS_DISABLED) ? DFCS_INACTIVE : 0));
pDC->DrawEdge(rect, EDGE_SUNKEN, BF_RECT);
// Must reduce the size of the "client" area of the button due to edge thickness.
rect.DeflateRect(Margins.cx, Margins.cy);
// Fill remaining area with colour
rect.right -= m_ArrowRect.Width();
CBrush brush( ((state & ODS_DISABLED) || m_crColourBk == CLR_DEFAULT)?
::GetSysColor(COLOR_3DFACE) : m_crColourBk);
CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
pDC->SelectStockObject(NULL_PEN);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
// Draw the window text (if any)
GetWindowText(m_strText);
if (m_strText.GetLength())
{
pDC->SetBkMode(TRANSPARENT);
if (state & ODS_DISABLED)
{
rect.OffsetRect(1,1);
pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
rect.OffsetRect(-1,-1);
pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
}
else
{
pDC->SetTextColor((m_crColourText == CLR_DEFAULT)? 0 : m_crColourText);
pDC->DrawText(m_strText, rect, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
}
}
// Draw focus rect
if (state & ODS_FOCUS)
{
rect.DeflateRect(1,1);
pDC->DrawFocusRect(rect);
}
}
示例5: onDrawItem
/// <summary>Custom draws an entire listview item</summary>
/// <param name="pDraw">Draw/Item data</param>
/// <param name="stage">Draw stage.</param>
/// <returns></returns>
bool ListViewCustomDraw::onDrawItem(NMLVCUSTOMDRAW* pDraw, Stage stage)
{
try
{
// DEBUG
//Console << "onDrawItem item=" << (int)pDraw->nmcd.dwItemSpec << " Stage=" << GetString(stage) << " state=" << pDraw->nmcd.uItemState << ENDL;
// PostPaint: Do nothing
if (stage == Stage::PostPaint)
return true;
// Init
CDC dc;
dc.Attach(pDraw->nmcd.hdc);
// Get item data
ItemData item((int)pDraw->nmcd.dwItemSpec, 0);
ListView.GetItemRect(item.Index, item.Rect, LVIR_BOUNDS);
item.Selected = ListView.GetItemState(item.Index, LVIS_SELECTED) != 0;
item.Focused = ListView.GetItemState(item.Index, LVIS_FOCUSED) != 0;
// Draw background
bool ListHasFocus = (::GetFocus() == ListView.GetSafeHwnd());
auto backColour = (item.Selected ? (ListHasFocus ? ActiveHighlight : InactiveHighlight) : ListView.GetBkColor());
dc.FillSolidRect(item.Rect, backColour);
// BugFix: check for header ctrl
if (!ListView.GetHeaderCtrl())
throw GenericException(HERE, L"Listview has no header ctrl");
// Draw sub items:
for (int count = ListView.GetHeaderCtrl()->GetItemCount(); item.SubItem < count; ++item.SubItem)
{
// Get sub-item rectangle
ListView.GetSubItemRect(item.Index, item.SubItem, LVIR_LABEL, item.Rect);
item.Rect.DeflateRect(GetSystemMetrics(SM_CXEDGE),0);
// Reset text colour [Invert if selected]
dc.SetTextColor(GetSysColor(item.Selected ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT));
// Allow derived-class to do drawing
onDrawSubItem(&dc, item);
}
// Draw Focus rect:
if (ListHasFocus && item.Focused)
{
ListView.GetItemRect(item.Index, item.Rect, LVIR_BOUNDS);
dc.DrawFocusRect(item.Rect);
}
// Cleanup
dc.Detach();
return true;
}
catch (ExceptionBase& e) {
Console.Log(HERE, e);
return false;
}
}
示例6: DrawItemFocusRect
/**
* DrawItemFocusRect()
*
* 指定されたアイテムにフォーカス矩形を表示する
* ・XORで描画するので2回呼べば矩形を消す
* ここは描画か消去か意識できないので呼び出し側で管理すること
* ・アイテムがスクロールされたら消される
*
*/
void CTouchListCtrl::DrawItemFocusRect( const int nItem )
{
CRect rcItem;
GetItemRect( nItem , rcItem , LVIR_BOUNDS);
CDC* pdc = GetDC();
pdc->DrawFocusRect( rcItem );
ReleaseDC(pdc);
}
示例7: OnMouseMove
void CPhylogenView::OnMouseMove(UINT nFlags, CPoint point)
{
CScrollView::OnMouseMove(nFlags, point);
// TODO: Add your message handler code here and/or call default CView
CGenedocDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
if ( pDoc->m_pPGBase != NULL ) {
CPhyloNode *pPNDoc = pDoc->m_pPGBase;
POSITION Pos = pPNDoc->m_PhyloList.GetHeadPosition();
while ( Pos != NULL ) {
CPhyloGenBase * pPGB = (CPhyloGenBase *)pPNDoc->m_PhyloList.GetNext(Pos);
if ( pPGB->m_Selected == 1 ) {
if ( !pPGB->m_ClientRect.PtInRect ( point ) ) {
CDC* pDC = GetDC();
CRect tRect = pPGB->m_ClientRect;
dc.LPtoDP( &tRect );
pDC->DrawFocusRect( tRect );
pPGB->m_Selected = 0;
ReleaseDC( pDC );
}
}
if ( pPGB->m_ClientRect.PtInRect ( point ) ) {
if ( pPGB->m_Selected == 0 ) {
CDC* pDC = GetDC();
pPGB->m_Selected = 1;
CRect tRect = pPGB->m_ClientRect;
dc.LPtoDP( &tRect );
pDC->DrawFocusRect( tRect );
ReleaseDC( pDC );
}
}
}
}
}
示例8: tRect
void
CPhylogenView::SetSelected(int Selection, int CheckScroll )
{
CGenedocDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
m_LastKeySelect = Selection;
CPhyloGenBase * pPGB;
POSITION Pos;
Pos = pDoc->m_pPGBase->m_PhyloList.GetHeadPosition();
while ( Pos != NULL ) {
pPGB = (CPhyloGenBase *)pDoc->m_pPGBase->m_PhyloList.GetNext(Pos);
if ( !Selection-- ) break;
}
CDC* pDC = GetDC();
CRect fRect = pPGB->m_ClientRect;
if ( CheckScroll ) {
// Check if Scroll Call need to be made.
CRect tRect ( m_ScrollPos, m_ViewSize );
CPoint Position1 = fRect.TopLeft();
Position1.x = 0;
CPoint Position2 = fRect.BottomRight();
Position2.x = 0;
if ( (!tRect.PtInRect ( Position1 )) || (!tRect.PtInRect ( Position2 )) ) {
CPoint tPos = m_ScrollPos;
int YPos = Position1.y;
if ( (YPos - (m_ViewSize.cy / 2)) < 0 ) {
YPos = 0;
} else {
YPos = (YPos - (m_ViewSize.cy / 2));
}
tPos.y = YPos < (m_MaxScrolls.cy - m_ViewSize.cy) ? YPos: (m_MaxScrolls.cy - m_ViewSize.cy);
tPos.x = Position1.x < (m_MaxScrolls.cx - m_ViewSize.cx) ? Position1.x: (m_MaxScrolls.cx - m_ViewSize.cx);
ScrollToPosition ( tPos );
m_ScrollPos = GetScrollPosition();
}
}
CClientDC dc(this);
OnPrepareDC(&dc);
pPGB->m_Selected = 1;
dc.LPtoDP( &fRect );
pDC->DrawFocusRect( fRect );
ReleaseDC( pDC );
}
示例9: DrawItem
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CIconComboBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CBrush *pOldBrush = NULL;
CPen *pOldPen = NULL;
//
// the icon is "disabled"
//
if( !IsWindowEnabled() )
{
SetDisabledBrushAndPen( lpDrawItemStruct, &pOldBrush, &pOldPen );
OnDrawIcon( lpDrawItemStruct );
ResetBrushAndPen( lpDrawItemStruct, pOldBrush, pOldPen );
return;
}
//
// the icon is "selected"
//
if( ( lpDrawItemStruct->itemState & ODS_SELECTED ) &&
( lpDrawItemStruct->itemAction & ( ODA_SELECT | ODA_DRAWENTIRE ) ) )
{
SetSelectedBrushAndPen( lpDrawItemStruct, &pOldBrush, &pOldPen );
OnDrawIcon( lpDrawItemStruct );
ResetBrushAndPen( lpDrawItemStruct, pOldBrush, pOldPen );
}
//
// the icon is "un-selected"
//
if( !( lpDrawItemStruct->itemState & ODS_SELECTED ) &&
( lpDrawItemStruct->itemAction & ( ODA_SELECT | ODA_DRAWENTIRE ) ) )
{
SetUnSelectedBrushAndPen( lpDrawItemStruct, &pOldBrush, &pOldPen );
OnDrawIcon( lpDrawItemStruct );
ResetBrushAndPen( lpDrawItemStruct, pOldBrush, pOldPen );
}
//
// icon gains focus
//
if( lpDrawItemStruct->itemAction & ODA_FOCUS )
{
// get the device context
CDC* pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
// render the focus rectangle
pDC->DrawFocusRect( &lpDrawItemStruct->rcItem );
}
}
示例10: DrawItem
void CColourButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc = lpDrawItemStruct->rcItem;
if (lpDrawItemStruct->CtlType == ODT_BUTTON)
{
// Draw 3D frame
if (lpDrawItemStruct->itemState & (ODS_SELECTED | ODS_DISABLED))
pDC->DrawEdge(rc, EDGE_SUNKEN, BF_RECT|BF_ADJUST);
else
pDC->DrawEdge(rc, EDGE_RAISED, BF_RECT|BF_ADJUST);
// Draw colour
pDC->FillSolidRect(rc, m_colour);
// if it has the focus, draw a dotted line
if (lpDrawItemStruct->itemState & ODS_FOCUS)
{
CRect rcFocus (rc);
rcFocus.DeflateRect (1, 1);
if (lpDrawItemStruct->itemState & ODS_SELECTED)
rcFocus.OffsetRect (-1, -1); // move text as button moves
pDC->DrawFocusRect (rcFocus);
}
// Draw button text
CString strText;
GetWindowText(strText);
COLORREF crOldColor;
// if colour is dark, use white, otherwise use black
if (((GetRValue (m_colour) & 0xFF) +
(GetGValue (m_colour) & 0xFF) +
(GetBValue (m_colour) & 0xFF) ) < (128 * 3))
crOldColor = pDC->SetTextColor(RGB(255,255,255));
else
crOldColor = pDC->SetTextColor(RGB(0,0,0));
if (lpDrawItemStruct->itemState & ODS_SELECTED)
rc.OffsetRect (-1, -1); // move text as button moves
pDC->DrawText (strText, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
pDC->SetTextColor(crOldColor);
}
}
示例11: DrawItem
void CColorSelector::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
CDC omDc;
omDc.Attach(lpDrawItemStruct->hDC);
UINT unButtonState = lpDrawItemStruct->itemState;
int nPushState = ((unButtonState & ODS_SELECTED) ? DFCS_PUSHED : 0) |
((unButtonState & ODS_DISABLED) ? DFCS_INACTIVE : 0);
CRect omItemRect = lpDrawItemStruct->rcItem;
CRect omArrowRect;
omArrowRect.left = max(0, omItemRect.Width()- GetSystemMetrics(SM_CXHTHUMB) - 3 );
omArrowRect.right = max(0, omItemRect.Width()-3);
omArrowRect.top = 3;
omArrowRect.bottom = max(omItemRect.Height()-3, GetSystemMetrics(SM_CYVTHUMB)-3);
omDc.DrawFrameControl(&omArrowRect, DFC_SCROLL, DFCS_SCROLLDOWN | nPushState);
// Create backgroung brush
CBrush brush( m_omColorBkg);
omDc.SelectStockObject(BLACK_PEN);
omDc.DrawEdge(&lpDrawItemStruct->rcItem, EDGE_RAISED, BF_RECT);
CRect omButtonRect;
omButtonRect.left = lpDrawItemStruct->rcItem.left+5;
omButtonRect.top = lpDrawItemStruct->rcItem.top+5;
omButtonRect.right = lpDrawItemStruct->rcItem.right - omArrowRect.Width()-5;// - omArrowRect.Width() ;
omButtonRect.bottom = lpDrawItemStruct->rcItem.bottom - 5;
//omButtonRect.DeflateRect(3, 3);
omDc.FillRect(omButtonRect, &brush);
// Select Old Brush
omDc.SelectObject(brush);
omButtonRect.DeflateRect(-1, -1);
omDc.Rectangle(omButtonRect);
if (unButtonState & ODS_FOCUS)
{
omButtonRect.DeflateRect(1,1);
omDc.DrawFocusRect(omButtonRect);
}
}
示例12: DrawItem
void CFontComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
ASSERT( lpDIS->CtlType == ODT_COMBOBOX );
// make sure this is a *real* item
if (lpDIS->itemID == -1)
return;
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
FONTITEM_PPG* pFI = (FONTITEM_PPG*)lpDIS->itemData; // pointer to a FONTITEM storied in item data
LOGFONT* pLF = &pFI->lf;
COLORREF crBk, crText;
TEXTMETRIC tm;
int x, y;
// Calculate the colors to use
crBk = pDC->SetBkColor(
GetSysColor(lpDIS->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW) );
crText = pDC->SetTextColor(
GetSysColor(lpDIS->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT) );
// Calculate the position of the text
pDC->GetTextMetrics( &tm );
x = LOWORD(GetDialogBaseUnits()) / 4;
y = (lpDIS->rcItem.bottom + lpDIS->rcItem.top - tm.tmHeight) / 2;
// Draw the text
pDC->ExtTextOut(lpDIS->rcItem.left + DX_BITMAP + 2 * x, y, ETO_CLIPPED | ETO_OPAQUE,
&lpDIS->rcItem,(LPCTSTR) pLF->lfFaceName,
lstrlen((LPCTSTR) pLF->lfFaceName), NULL );
// Put the colors back as they were
pDC->SetTextColor( crText );
pDC->SetBkColor( crBk );
// Draw the TrueType bitmap
if (pFI->dwFontType & TRUETYPE_FONTTYPE)
{
int dy;
dy = ((lpDIS->rcItem.bottom - lpDIS->rcItem.top) - DY_BITMAP) / 2;
_AfxDrawMaskedBitmap(pDC, &m_bmpTrueType, &m_bmpMask,
x, lpDIS->rcItem.top + dy, DX_BITMAP, DY_BITMAP);
}
// Draw the focus rect if needed
if (lpDIS->itemState & ODS_FOCUS)
pDC->DrawFocusRect( &lpDIS->rcItem );
}
示例13: DrawItem
void CPushCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *pdc;
int bmpId;
CBitmap bitmap;
BITMAP bmp;
CPictureHolder picHolder;
CRect rcSrcBounds;
CPen* pOldPen;
RECT rect;
SHORT inflate;
pdc = CDC::FromHandle(lpDrawItemStruct->hDC);
switch (lpDrawItemStruct->itemAction)
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
// Load "up" or "down" bitmap depending on selection state
bmpId = (lpDrawItemStruct->itemState & ODS_SELECTED) ? IDB_DOWNBITMAP
: IDB_UPBITMAP;
bitmap.LoadBitmap(bmpId);
bitmap.GetObject(sizeof(BITMAP), &bmp);
rcSrcBounds.right = bmp.bmWidth;
rcSrcBounds.bottom = bmp.bmHeight;
// Create picture and render
picHolder.CreateFromBitmap((HBITMAP)bitmap.m_hObject, NULL, FALSE);
picHolder.Render(pdc, lpDrawItemStruct->rcItem, rcSrcBounds);
break;
case ODA_FOCUS:
// Just draw focus rect
pOldPen = (CPen*)pdc->SelectStockObject(BLACK_PEN);
if (lpDrawItemStruct->itemState & ODS_FOCUS)
{
CopyRect((LPRECT)&rect, (LPRECT)&lpDrawItemStruct->rcItem);
inflate = (SHORT)min(3,min(rect.right - rect.left + 1,
rect.bottom - rect.top + 1) / 5);
InflateRect(&rect, -inflate, -inflate);
pdc->DrawFocusRect(&rect);
}
pdc->SelectObject(pOldPen);
break;
}
}
示例14: DrawItem
// this is a verbatim copy of CCheckListBox::DrawItem purely
// to handle the fact that the text is rendered flush with the
// left edge of the background and focus rect.
// the only thing we change is to add 2 pixels to the origin
// of the text
void CCheckListBoxEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// You must override DrawItem and MeasureItem for LBS_OWNERDRAWVARIABLE
ASSERT((GetStyle() & (LBS_OWNERDRAWFIXED | LBS_HASSTRINGS)) ==
(LBS_OWNERDRAWFIXED | LBS_HASSTRINGS));
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
if (((LONG)(lpDrawItemStruct->itemID) >= 0) &&
(lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT)))
{
int cyItem = GetItemHeight(lpDrawItemStruct->itemID);
BOOL fDisabled = !IsWindowEnabled() || !IsEnabled(lpDrawItemStruct->itemID);
COLORREF newTextColor = fDisabled ?
RGB(0x80, 0x80, 0x80) : GetSysColor(COLOR_WINDOWTEXT); // light gray
COLORREF oldTextColor = pDC->SetTextColor(newTextColor);
COLORREF newBkColor = GetSysColor(COLOR_WINDOW);
COLORREF oldBkColor = pDC->SetBkColor(newBkColor);
if (newTextColor == newBkColor)
newTextColor = RGB(0xC0, 0xC0, 0xC0); // dark gray
if (!fDisabled && ((lpDrawItemStruct->itemState & ODS_SELECTED) != 0))
{
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
pDC->SetBkColor(GetSysColor(COLOR_HIGHLIGHT));
}
if (m_cyText == 0)
VERIFY(cyItem >= CalcMinimumItemHeight());
CString strText;
GetText(lpDrawItemStruct->itemID, strText);
pDC->ExtTextOut(lpDrawItemStruct->rcItem.left + 2,
lpDrawItemStruct->rcItem.top + max(0, (cyItem - m_cyText) / 2),
ETO_OPAQUE, &(lpDrawItemStruct->rcItem), strText, strText.GetLength(), NULL);
pDC->SetTextColor(oldTextColor);
pDC->SetBkColor(oldBkColor);
}
if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0)
pDC->DrawFocusRect(&(lpDrawItemStruct->rcItem));
}
示例15: DrawItem
void CLineCombo::DrawItem(LPDRAWITEMSTRUCT lpMIS)
{
CDC *pDC = CDC::FromHandle(lpMIS->hDC);
RECT *pRect = &lpMIS->rcItem;
int H = pRect->bottom - pRect->top;
int W = pRect->right - pRect->left;
CPoint pt1,pt2;
pt1.x = 4;
pt1.y = pRect->top + H/2;
pt2.x = W-4;
pt2.y = pRect->top + H/2;
/* CPen pen;
if (!pen.CreatePen(PS_DASHDOT, 1, RGB(0,0,0)))
return;
CPen* pOldPen=pDC->SelectObject(&pen);*/
int i=lpMIS->itemID;
CADLType* pLType=(CADLType*)m_pGraphics->m_LTypes.GetAt(i);
// return;
CreatePenStyle(pDC,pLType);
if (lpMIS->itemAction & ODA_DRAWENTIRE)
{
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}
if ((lpMIS->itemState & ODS_SELECTED) &&
(lpMIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
{
CBrush br(0x6A240A);
pDC->FillRect(&lpMIS->rcItem,&br);
pDC->DrawFocusRect(&lpMIS->rcItem);
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}
if (!(lpMIS->itemState & ODS_SELECTED) &&
(lpMIS->itemAction & ODA_SELECT))
{
CBrush br(RGB(255,255,255));
pDC->FillRect(&lpMIS->rcItem,&br);
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}
}