コード例 #1
2
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);
    }
}
コード例 #2
1
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);
    }
}
コード例 #3
1
ファイル: pushctl.cpp プロジェクト: jetlive/skiaming
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;
	}
}
コード例 #4
0
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();
}
コード例 #5
0
ファイル: AboutDlg.cpp プロジェクト: jovibor/Shutdown
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;
	}
	}
}
コード例 #6
0
      /// <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;
         }
      }
コード例 #7
0
ファイル: Phylovw.cpp プロジェクト: karlnicholas/GeneDoc
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;
}
コード例 #8
0
ファイル: TouchListCtrl.cpp プロジェクト: takke/MZ3
/**
 * DrawItemFocusRect()
 *
 * 指定されたアイテムにフォーカス矩形を表示する
 * ・XORで描画するので2回呼べば矩形を消す
 *   ここは描画か消去か意識できないので呼び出し側で管理すること
 * ・アイテムがスクロールされたら消される
 *
 */
void CTouchListCtrl::DrawItemFocusRect( const int nItem )
{
	CRect rcItem;
	GetItemRect( nItem , rcItem , LVIR_BOUNDS);
	CDC* pdc = GetDC();
	pdc->DrawFocusRect( rcItem );
	ReleaseDC(pdc);
}
コード例 #9
0
ファイル: Phylovw.cpp プロジェクト: karlnicholas/GeneDoc
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 );
                }
            }
        }
    }

}
コード例 #10
0
ファイル: Phylovw.cpp プロジェクト: karlnicholas/GeneDoc
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 );

}
コード例 #11
0
//-----------------------------------------------------------------------------
// 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 );
    }
}
コード例 #12
0
ファイル: ButtonColour.cpp プロジェクト: RKelson93/mushclient
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);


	}
}
コード例 #13
0
ファイル: ppgfont.cpp プロジェクト: anyue100/winscp
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 );
}
コード例 #14
0
ファイル: checklistboxex.cpp プロジェクト: jithuin/infogeezer
// 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
0
ファイル: LineCombo.cpp プロジェクト: yaoyushun/sdcad
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); 
	}
}
コード例 #16
0
void CCustomButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); //Get device context object
	CRect rt;
	rt = lpDrawItemStruct->rcItem; //Get button rect
	UINT state = lpDrawItemStruct->itemState; //Get state of the button

	if ( (state & ODS_DISABLED) ) // If it is pressed
	{
		dc.FillSolidRect(rt, RGB(80, 80, 80)); 
		dc.SetTextColor(RGB(120,120,120)); 
	}
	else
	{
		dc.FillSolidRect(rt, RGB(80, 80, 80));
		dc.SetTextColor(RGB(180,150,0)); 
	}
	CString strTemp;
	GetWindowText(strTemp);
	dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE); 


	if ( (state & ODS_SELECTED) ) // If it is pressed
	{
		dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT);
	}
	else
	{
		dc.DrawEdge(rt,EDGE_BUMP,BF_RECT); 
	}

	if ( (state & ODS_FOCUS ) ) // If the button is focused
	{
		// Draw a focus rect which indicates the user
		// that the button is focused
		int iChange = 3;
		rt.top += iChange;
		rt.left += iChange;
		rt.right -= iChange;
		rt.bottom -= iChange;
		dc.DrawFocusRect(rt);
	}
	dc.Detach();
}
コード例 #17
0
ファイル: CustomButton.cpp プロジェクト: the-reverend/Win32xx
/*============================================================================*/
	void CustomButton::
DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)               		/*

	Custom draw the item specified in lpDrawItemStruct: here a button.
	Invoked by the view for the owner-drawn button in response to the
	WM_DRAWITEM system message. An owner-drawn button has the BS_OWNERDRAW
	style set. Also see the BS_ style values.
	
	Note: this procedure can show the focus rectangle of the button when the
	button has focus. Howeever, the focus does not appear to be cancelled
	when another control recieves the focus, and the non-owner-draw form
	of push buttons does not have this rectangle present when pressed
*-----------------------------------------------------------------------------*/
{
	  // get the device context and attach the button handle to it
	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); 
	  // determine the button rectangle
	CRect rect = lpDrawItemStruct->rcItem;
	  // draw in the button text
	dc.DrawText(GetWindowText(), -1, rect, DT_CENTER | DT_VCENTER |
	    DT_SINGLELINE);
	  // get the current state of the button
	UINT state = lpDrawItemStruct->itemState;
	if ( (state & ODS_SELECTED) )	// if it is pressed
	{
		dc.DrawEdge(rect, EDGE_SUNKEN, BF_RECT); // draw a sunken face
	}
	else
	{
		dc.DrawEdge(rect, EDGE_RAISED, BF_RECT); // draw a raised face
	}
	  // draw the focus rectangle, a dotted rectangle just inside the
	  // button rectangle when the button has the focus.
	if (lpDrawItemStruct->itemAction & ODA_FOCUS)
	{
		int iChange = 3;
		rect.top    += iChange;
		rect.left   += iChange;
		rect.right  -= iChange;
		rect.bottom -= iChange;
		dc.DrawFocusRect(rect);
	}
	dc.Detach();
}
コード例 #18
0
void CFontComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	ASSERT(lpDIS->CtlType == ODT_COMBOBOX);
	int id = (int)(WORD)lpDIS->itemID;

	CDC *pDC = CDC::FromHandle(lpDIS->hDC);
	CRect rc(lpDIS->rcItem);
	if (lpDIS->itemState & ODS_FOCUS)
		pDC->DrawFocusRect(rc);
	int nIndexDC = pDC->SaveDC();

	CBrush brushFill;
	if (lpDIS->itemState & ODS_SELECTED)
	{
		brushFill.CreateSolidBrush(::GetSysColor(COLOR_HIGHLIGHT));
		pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
	}
	else
		brushFill.CreateSolidBrush(pDC->GetBkColor());
	pDC->SetBkMode(TRANSPARENT);
	pDC->FillRect(rc, &brushFill);

	CFontDesc* pDesc= (CFontDesc*)lpDIS->itemData;
	ASSERT(pDesc != NULL);
	DWORD dwData = pDesc->m_dwFlags;
	if (dwData & (TT_FONT|DEVICE_FONT)) // truetype or device flag set by SetItemData
	{
		CDC dc;
		dc.CreateCompatibleDC(pDC);
		CBitmap* pBitmap = dc.SelectObject(&m_bmFontType);
		if (dwData & TT_FONT)
			pDC->BitBlt(rc.left, rc.top, BMW, BMH, &dc, BMW, 0, SRCAND);
		else // DEVICE_FONT
			pDC->BitBlt(rc.left, rc.top, BMW, BMH, &dc, 0, 0, SRCAND);
		dc.SelectObject(pBitmap);
	}

	rc.left += BMW + 6;
	CString strText;
	GetLBText(id, strText);
	pDC->TextOut(rc.left,rc.top,strText,strText.GetLength());

	pDC->RestoreDC(nIndexDC);
}
コード例 #19
0
ファイル: PicDrawC.cpp プロジェクト: pdrezet/brix
void CPicDrawC::DrawItem(LPDRAWITEMSTRUCT lpdis, bool bHasFocus)
{
	if (lpdis->itemID==(UINT)-1) return;

	CDC dc;
	CRect rect = lpdis->rcItem;
	
	
	ASSERT( lpdis->itemID >= 0 );
	const int nIndex = lpdis->itemID;

	dc.Attach(lpdis->hDC);

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

	if ((lpdis->itemAction | ODA_SELECT) &&
	(lpdis->itemState  & ODS_SELECTED))	{
		dc.FillSolidRect(rect, ::GetSysColor(COLOR_HIGHLIGHT));
		if(bHasFocus) {
			dc.DrawFocusRect(rect);
		}	
	}
	else {      
		dc.FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));  
	}

	HBITMAP hbmp = (HBITMAP)lpdis->itemData;
	CDC MemDC;
	MemDC.CreateCompatibleDC(&dc);
	MemDC.SelectObject(hbmp);
	dc.BitBlt(rect.left+5, rect.top+1, PicSizeX, PicSizeY, &MemDC, 0, 0, SRCCOPY);
	
	// Reset the background color and the text color back to their
	// original values.
	dc.SetTextColor(crOldTextColor);
	dc.SetBkColor(crOldBkColor);	

	dc.Detach();

}
コード例 #20
0
ファイル: PropertyList.cpp プロジェクト: Deepfreeze32/taken
void CPropertyList::DrawItem(LPDRAWITEMSTRUCT lpDIS) {
	CDC dc;
	dc.Attach(lpDIS->hDC);
	CRect rectFull = lpDIS->rcItem;
	CRect rect = rectFull;
	if (m_nDivider==0) {
		m_nDivider = rect.Width() / 2;
	}
	rect.left = m_nDivider;
	CRect rect2 = rectFull;
	rect2.right = rect.left - 1;
	UINT nIndex = lpDIS->itemID;

	if (nIndex != (UINT) -1) {
		//get the CPropertyItem for the current row
		CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(nIndex);
		//draw two rectangles, one for each row column
		if (pItem->m_nItemType == PIT_VAR) {
			dc.FillSolidRect(rect2,RGB(220,220,220));
		} else {
			dc.FillSolidRect(rect2,RGB(192,192,192));
		}
		dc.DrawEdge(rect2,EDGE_SUNKEN,BF_BOTTOMRIGHT);
		dc.DrawEdge(rect,EDGE_SUNKEN,BF_BOTTOM);
		
		if (lpDIS->itemState == ODS_SELECTED) {
			dc.DrawFocusRect(rect2);
		}

		//write the property name in the first rectangle
		dc.SetBkMode(TRANSPARENT);
		dc.DrawText(pItem->m_propName,CRect(rect2.left+3,rect2.top+3,
											rect2.right-3,rect2.bottom+3),
					DT_LEFT | DT_SINGLELINE);

		//write the initial property value in the second rectangle
		dc.DrawText(pItem->m_curValue,CRect(rect.left+3,rect.top+3, rect.right+3,rect.bottom+3), DT_LEFT | (pItem->m_nItemType == PIT_VAR) ? DT_WORDBREAK : DT_SINGLELINE);
	}
	dc.Detach();
}
コード例 #21
0
ファイル: MyBtn.cpp プロジェクト: zhanghonghe/GeneralUtility
void CMyBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{

	 CDC dc;
	dc.Attach(lpDrawItemStruct->hDC); //Get device context object
	CRect rt;
	rt = lpDrawItemStruct->rcItem; //Get button rect
 
	dc.FillSolidRect(rt, RGB(0, 0, 255)); //Fill button with blue color
 
	UINT state = lpDrawItemStruct->itemState; //Get state of the button
	if ( (state & ODS_SELECTED) ) // If it is pressed
	{
	dc.DrawEdge(rt,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
	}
	else
	{
	dc.DrawEdge(rt,EDGE_RAISED,BF_RECT); // Draw a raised face
	}
 
	dc.SetTextColor(RGB(255,255,120));
	// Set the color of the caption to be yellow
	CString strTemp;
	GetWindowText(strTemp);
	// Get the caption which have been set
	dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
	// Draw out the caption
	if ( (state & ODS_FOCUS ) ) // If the button is focused
	{
	// Draw a focus rect which indicates the user
	// that the button is focused
	int iChange = 3;
	rt.top += iChange;
	rt.left += iChange;
	rt.right -= iChange;
	rt.bottom -= iChange;
	dc.DrawFocusRect(rt);
	}
	dc.Detach();
}
コード例 #22
0
ファイル: ColorComboBox.cpp プロジェクト: lincoln56/robinerp
void CColorComboBox::DrawItem(LPDRAWITEMSTRUCT lp/*lpDrawItemStruct*/)
{

	CDC dc;
	dc.Attach(lp->hDC);
	CRect rc(lp->rcItem);
	CBrush brush;
	switch(lp->itemID)
	{
	case 0:	brush.CreateSolidBrush(RGB(0,0,0));				break;
	case 1:	brush.CreateSolidBrush(RGB(128,0,0));			break;
	case 2:	brush.CreateSolidBrush(RGB(0,128,0));			break;
	case 3:	brush.CreateSolidBrush(RGB(128,128,0));			break;
	case 4:	brush.CreateSolidBrush(RGB(0,0,128));			break;
	case 5:	brush.CreateSolidBrush(RGB(128,0,128));			break;
	case 6:	brush.CreateSolidBrush(RGB(0,128,128));			break;
	case 7:	brush.CreateSolidBrush(RGB(128,128,128));		break;
	case 8:	brush.CreateSolidBrush(RGB(255,0,0));			break;
	case 9:	brush.CreateSolidBrush(RGB(0,255,0));			break;
	case 10:	brush.CreateSolidBrush(RGB(255,255,0));		break;
	case 11:	brush.CreateSolidBrush(RGB(0,0,255));		break;
	case 12:	brush.CreateSolidBrush(RGB(255,0,255));		break;
	case 13:	brush.CreateSolidBrush(RGB(0,255,255));		break;
	case 14:	brush.CreateSolidBrush(RGB(255,255,255));	break;
	}
	rc.InflateRect(-2,-2);
	dc.FillRect(rc,&brush);
	if(lp->itemState && ODS_SELECTED)
		dc.DrawFocusRect(rc);

	/// {{Added by zxd 20100709 释放GDI资源
	brush.DeleteObject();
	/// Added by zxd 20100709 释放GDI资源}}

	dc.Detach();

	// TODO:  添加您的代码以绘制指定项
}
コード例 #23
0
ファイル: BtnST.cpp プロジェクト: CrawlingForward/BWChess
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
#ifdef ST_USE_MEMDC
  CDC  *pdrawDC = CDC::FromHandle(lpDIS->hDC);
  CMemDC memDC(pdrawDC);
  CDC  *pDC = &memDC;
#else	
  CDC* pDC = CDC::FromHandle(lpDIS->hDC);
#endif

  CPen *pOldPen;
  BOOL bIsPressed  = (lpDIS->itemState & ODS_SELECTED);
  BOOL bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
  BOOL bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

  CRect itemRect = lpDIS->rcItem;

  if (m_bIsFlat == FALSE)
  {
	if (bIsFocused)
	{
	  CBrush br(RGB(0,0,0));  
	  pDC->FrameRect(&itemRect, &br);
	  itemRect.DeflateRect(1, 1);
	}
  }

  // Prepare draw... paint button's area with background color
  COLORREF bgColor;
  if ((m_MouseOnButton == TRUE) || (bIsPressed))
	bgColor = GetActiveBgColor();
  else
	bgColor = GetInactiveBgColor();

  CBrush br(bgColor);
  pDC->FillRect(&itemRect, &br);

	// Disegno lo sfondo del bottone
//CBrush br(GetSysColor(COLOR_BTNFACE));  
//pDC->FillRect(&itemRect, &br);

  // Draw pressed button
  if (bIsPressed)
  {
	if (m_bIsFlat == TRUE)
	{
	  if (m_bDrawBorder == TRUE)
	  {
		CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // Bianco
		CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Grigio scuro

		// Disegno i bordi a sinistra e in alto
		// Dark gray line
		pOldPen = pDC->SelectObject(&penBtnShadow);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.left, itemRect.top);
		pDC->LineTo(itemRect.right, itemRect.top);
		// Disegno i bordi a destra e in basso
		// White line
		pDC->SelectObject(penBtnHiLight);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.top-1);
		//
		pDC->SelectObject(pOldPen);
	  }
	}
	else    
	{
	  CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
	  pDC->FrameRect(&itemRect, &brBtnShadow);
	}
  }
  else // ...else draw non pressed button
  {
	CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
	CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
	CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
	CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

	if (m_bIsFlat == TRUE)
	{
	  if (m_MouseOnButton == TRUE && m_bDrawBorder == TRUE)
	  {
		// Disegno i bordi a sinistra e in alto
		// White line
		pOldPen = pDC->SelectObject(&penBtnHiLight);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.left, itemRect.top);
		pDC->LineTo(itemRect.right, itemRect.top);
		// Disegno i bordi a destra e in basso
		// Dark gray line
		pDC->SelectObject(penBtnShadow);
		pDC->MoveTo(itemRect.left, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
		pDC->LineTo(itemRect.right-1, itemRect.top-1);
		//
		pDC->SelectObject(pOldPen);
	  }
	}
	else
	{
	  // Disegno i bordi a sinistra e in alto
	  // White line
	  pOldPen = pDC->SelectObject(&penBtnHiLight);
	  pDC->MoveTo(itemRect.left, itemRect.bottom-1);
	  pDC->LineTo(itemRect.left, itemRect.top);
	  pDC->LineTo(itemRect.right, itemRect.top);
	  // Light gray line
	  pDC->SelectObject(pen3DLight);
	  pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);
	  pDC->LineTo(itemRect.left+1, itemRect.top+1);
	  pDC->LineTo(itemRect.right, itemRect.top+1);
	  // Disegno i bordi a destra e in basso
	  // Black line
	  pDC->SelectObject(pen3DDKShadow);
	  pDC->MoveTo(itemRect.left, itemRect.bottom-1);
	  pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
	  pDC->LineTo(itemRect.right-1, itemRect.top-1);
	  // Dark gray line
	  pDC->SelectObject(penBtnShadow);
	  pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);
	  pDC->LineTo(itemRect.right-2, itemRect.bottom-2);
	  pDC->LineTo(itemRect.right-2, itemRect.top);
	  //
	  pDC->SelectObject(pOldPen);
	}
  }

  // Read the button title
  CString sTitle;
  GetWindowText(sTitle);

  // If we don't want the title displayed
  if (m_bShowText == FALSE) sTitle.Empty();

  CRect captionRect = lpDIS->rcItem;

  // Draw the icon
  if (m_hIconIn != NULL)
  {
	DrawTheIcon(pDC, &sTitle, &lpDIS->rcItem, &captionRect, bIsPressed, bIsDisabled);
  }

  // Write the button title (if any)
  if (sTitle.IsEmpty() == FALSE)
  {
	// Disegno la caption del bottone
	// Se il bottone e' premuto muovo la captionRect di conseguenza
	if (bIsPressed)
	  captionRect.OffsetRect(1, 1);
	
	// ONLY FOR DEBUG 
	// Evidenzia il rettangolo in cui verra' centrata la caption 
	//CBrush brBtnShadow(RGB(255, 0, 0));
	//pDC->FrameRect(&captionRect, &brBtnShadow);

#ifdef ST_USE_MEMDC
	// Get dialog's font
	CFont *pCurrentFont = GetFont(); 
	CFont *pOldFont = pDC->SelectObject(pCurrentFont);
#endif
	if ((m_MouseOnButton == TRUE) || (bIsPressed)) 
	{
	  pDC->SetTextColor(GetActiveFgColor());
	  pDC->SetBkColor(GetActiveBgColor());
	} 
	else 
	{
	  pDC->SetTextColor(GetInactiveFgColor());
	  pDC->SetBkColor(GetInactiveBgColor());
	}
	// Center text
	CRect centerRect = captionRect;
	pDC->DrawText(sTitle, -1, captionRect, DT_SINGLELINE|DT_CALCRECT);
	captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, (centerRect.Height() - captionRect.Height())/2);
	/* RFU
	captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
	captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
	*/

	pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), 
				   TRUE, 0, (CBrush*)NULL);
#ifdef ST_USE_MEMDC
	pDC->SelectObject(pOldFont);
#endif
  }

  if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
  {
	// Draw the focus rect
	if (bIsFocused)
	{
	  CRect focusRect = itemRect;
	  focusRect.DeflateRect(3, 3);
	  pDC->DrawFocusRect(&focusRect);
	}
  }
} // End of DrawItem
コード例 #24
0
//******************************************************************************************
void CBCGFontComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	if (m_Images.GetSafeHandle () == NULL)
	{
		CBCGLocalResource locaRes;
		m_Images.Create (IDB_BCGBARRES_FONT, nImageWidth, 0, RGB (255, 0, 255));
	}

	ASSERT (lpDIS->CtlType == ODT_COMBOBOX);

	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	ASSERT_VALID (pDC);

	CRect rc = lpDIS->rcItem;
	
	if (lpDIS->itemState & ODS_FOCUS)
	{
		pDC->DrawFocusRect(rc);
	}

	int nIndexDC = pDC->SaveDC ();

	CBrush brushFill;
	if (lpDIS->itemState & ODS_SELECTED)
	{
		brushFill.CreateSolidBrush (::GetSysColor (COLOR_HIGHLIGHT));
		pDC->SetTextColor (::GetSysColor (COLOR_HIGHLIGHTTEXT));
	}
	else
	{
		brushFill.CreateSolidBrush (pDC->GetBkColor());
	}

	pDC->SetBkMode(TRANSPARENT);
	pDC->FillRect(rc, &brushFill);

	int id = (int)lpDIS->itemID;
	if (id >= 0)
	{
		CBCGFontDesc* pDesc= (CBCGFontDesc*)lpDIS->itemData;
		if (pDesc != NULL)
		{
			if (pDesc->m_nType & (DEVICE_FONTTYPE | TRUETYPE_FONTTYPE))
			{
				CPoint ptImage (rc.left, rc.top + (rc.Height () - nImageHeight) / 2);
				m_Images.Draw (pDC, (pDesc->m_nType & DEVICE_FONTTYPE) ? 0 : 1, 
					ptImage, ILD_NORMAL);
			}

			rc.left += nImageWidth + 6;
		}
		else
		{
			rc.left += 2;
		}

		CString strText;
		GetLBText (id, strText);

		pDC->DrawText (strText, rc, DT_SINGLELINE | DT_VCENTER);
	}

	pDC->RestoreDC (nIndexDC);
}
コード例 #25
0
void CButtonST::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
    CDC*    pDC = CDC::FromHandle(lpDIS->hDC);

    CPen    *pOldPen;

    // Checkbox or Radiobutton style ?
    if (m_bIsCheckBox == TRUE)
    {
        m_bIsPressed  =  (lpDIS->itemState & ODS_SELECTED) || (m_nCheck != 0);
        //m_bIsPressed = TRUE;
    }
    // Normal button OR other button style ...
    else
    {
        m_bIsPressed = (lpDIS->itemState & ODS_SELECTED);
    }

    m_bIsFocused  = (lpDIS->itemState & ODS_FOCUS);
    m_bIsDisabled = (lpDIS->itemState & ODS_DISABLED);

    CRect itemRect = lpDIS->rcItem;

    pDC->SetBkMode(TRANSPARENT);

    if (m_bIsFlat == FALSE)
    {
        if (m_bIsFocused || (GetDefault() == TRUE))
        {
            CBrush br(RGB(0,0,0));  
            pDC->FrameRect(&itemRect, &br);
            itemRect.DeflateRect(1, 1);
        } // if
    } // if

    // Prepare draw... paint button background

    // Draw transparent?
    if (m_bDrawTransparent == TRUE)
    {
        PaintBk(pDC);
    }
    else
    {
        OnDrawBackground(pDC, &itemRect);
    }

    // Draw pressed button
    if (m_bIsPressed)
    {
		CRect captionRect1 = lpDIS->rcItem;
        if (m_bIsFlat == TRUE)
        {
            if (m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
		
            }
        }
        else    
        {
            CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
            pDC->FrameRect(&itemRect, &brBtnShadow);
        }
    }
    else // ...else draw non pressed button
    {
        CPen penBtnHiLight(PS_SOLID, 0, GetSysColor(COLOR_BTNHILIGHT)); // White
        CPen pen3DLight(PS_SOLID, 0, GetSysColor(COLOR_3DLIGHT));       // Light gray
        CPen penBtnShadow(PS_SOLID, 0, GetSysColor(COLOR_BTNSHADOW));   // Dark gray
        CPen pen3DDKShadow(PS_SOLID, 0, GetSysColor(COLOR_3DDKSHADOW)); // Black

        if (m_bIsFlat == TRUE)
        {
            if (m_bMouseOnButton && m_bDrawBorder)
            {
                OnDrawBorder(pDC, &itemRect);
            }
        }
        else
        {
            // Draw top-left borders
            // White line
            pOldPen = pDC->SelectObject(&penBtnHiLight);
            pDC->MoveTo(itemRect.left, itemRect.bottom-1);
            pDC->LineTo(itemRect.left, itemRect.top);
            pDC->LineTo(itemRect.right, itemRect.top);
            // Light gray line
            pDC->SelectObject(pen3DLight);
            pDC->MoveTo(itemRect.left+1, itemRect.bottom-1);
            pDC->LineTo(itemRect.left+1, itemRect.top+1);
            pDC->LineTo(itemRect.right, itemRect.top+1);
            // Draw bottom-right borders
            // Black line
            pDC->SelectObject(pen3DDKShadow);
            pDC->MoveTo(itemRect.left, itemRect.bottom-1);
            pDC->LineTo(itemRect.right-1, itemRect.bottom-1);
            pDC->LineTo(itemRect.right-1, itemRect.top-1);
            // Dark gray line
            pDC->SelectObject(penBtnShadow);
            pDC->MoveTo(itemRect.left+1, itemRect.bottom-2);
            pDC->LineTo(itemRect.right-2, itemRect.bottom-2);
            pDC->LineTo(itemRect.right-2, itemRect.top);
            //
            pDC->SelectObject(pOldPen);
        }
    }

    // Read the button's title
    CString sTitle;
    GetWindowText(sTitle);

    CRect captionRect = lpDIS->rcItem;

    // Draw the icon
    if (m_csIcons[0].hIcon != NULL)
    {
        DrawTheIcon(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
    }

    if (m_csBitmaps[0].hBitmap != NULL)
    {
        pDC->SetBkColor(RGB(255,255,255));
        DrawTheBitmap(pDC, !sTitle.IsEmpty(), &lpDIS->rcItem, &captionRect, m_bIsPressed, m_bIsDisabled);
    } // if

    // Write the button title (if any)
    if (sTitle.IsEmpty() == FALSE)
    {
        // Draw the button's title
        // If button is pressed then "press" title also
        if (m_bIsPressed && m_bIsCheckBox == FALSE)
        {
            //将偏移1像素的粗体显示效果去除。
            captionRect.OffsetRect(0, 0);
        }
    
        // ONLY FOR DEBUG 
        //CBrush brBtnShadow(RGB(255, 0, 0));
        //pDC->FrameRect(&captionRect, &brBtnShadow);

        /*
        if ((m_bMouseOnButton == TRUE) || (bIsPressed)) 
        {
            pDC->SetTextColor(GetActiveFgColor());
            pDC->SetBkColor(GetActiveBgColor());
        } 
        else 
        {
            pDC->SetTextColor(GetInactiveFgColor());
            pDC->SetBkColor(GetInactiveBgColor());
        }
        */
        // Center text
        CRect centerRect = captionRect;
        pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER | DT_CALCRECT);
        captionRect.OffsetRect((centerRect.Width() - captionRect.Width())/2, 
            (centerRect.Height() - captionRect.Height())/2);
        /* RFU
        captionRect.OffsetRect(0, (centerRect.Height() - captionRect.Height())/2);
        captionRect.OffsetRect((centerRect.Width() - captionRect.Width())-4, (centerRect.Height() - captionRect.Height())/2);
        */

        pDC->SetBkMode(TRANSPARENT);
        /*
        pDC->DrawState(captionRect.TopLeft(), captionRect.Size(), (LPCTSTR)sTitle, (bIsDisabled ? DSS_DISABLED : DSS_NORMAL), 
                        TRUE, 0, (CBrush*)NULL);
        */
        if (m_bIsDisabled)
        {
            captionRect.OffsetRect(1, 1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DHILIGHT));
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
            captionRect.OffsetRect(-1, -1);
            pDC->SetTextColor(::GetSysColor(COLOR_3DSHADOW));
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
        }
        else
        {
            if (m_bMouseOnButton || m_bIsPressed) 
            {
                pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_IN]);
                pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_IN]);
            }
            else 
            {
                pDC->SetTextColor(m_crColors[BTNST_COLOR_FG_OUT]);
                pDC->SetBkColor(m_crColors[BTNST_COLOR_BK_OUT]);
            }

            if(m_bBigDaddy)
            {
                if(m_bIsFlat == TRUE)
                {
                    if (m_bDrawBorder)
                    {
                        OnDrawBorder(pDC, &itemRect);
                    }
                }
                else
                {
                    CBrush brBtnShadow(RGB(255,255,0));
                    pDC->FrameRect(&itemRect, &brBtnShadow);
                }
            }
            pDC->DrawText(sTitle, -1, captionRect, DT_WORDBREAK | DT_CENTER);
        }
    }

    if (m_bIsFlat == FALSE || (m_bIsFlat == TRUE && m_bDrawFlatFocus == TRUE))
    {
        // Draw the focus rect
        if (m_bIsFocused)
        {
            CRect focusRect = itemRect;
            focusRect.DeflateRect(3, 3);
            pDC->DrawFocusRect(&focusRect);
        } // if
    } // if
} // End of DrawItem
コード例 #26
0
void CEditListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
	//draw each item.set txt color,bkcolor....
	NMLVCUSTOMDRAW* pNMLVCustomDraw = (NMLVCUSTOMDRAW*)pNMHDR;
	
	// Take the default processing unless we set this to something else below.
	*pResult = CDRF_DODEFAULT;
	
	// First thing - check the draw stage. If it's the control's prepaint
	// stage, then tell Windows we want messages for every item.
	
	if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
	{
		*pResult = CDRF_NOTIFYITEMDRAW;
	}
	else if (pNMLVCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
	{
		// This is the notification message for an item.  We'll request
		// notifications before each subitem's prepaint stage.
		*pResult = CDRF_NOTIFYSUBITEMDRAW;
	}
	else if (pNMLVCustomDraw->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
	{
		// store the colors back in the NMLVCUSTOMDRAW struct
		// but it's effective only when *pResult = CDRF_DODEFAULT 

		//	pNMLVCustomDraw->clrText = RGB(0, 0, 255);
		//	pNMLVCustomDraw->clrTextBk = RGB(0, 255, 0);
		//	*pResult = CDRF_DODEFAULT;
		
		// This is the prepaint stage for a subitem. Here's where we set the
		// item's text and background colors. Our return value will tell
		// Windows to draw the subitem itself, but it will use the new colors
		// we set here.
		int iItem = (int)pNMLVCustomDraw->nmcd.dwItemSpec;
		int iSubItem = pNMLVCustomDraw->iSubItem;
		
		CDC* pDC = CDC::FromHandle(pNMLVCustomDraw->nmcd.hdc);
		
		CString strItemText = GetItemText(iItem, iSubItem);
		CRect rcItem, rcText;
		GetSubItemRect(iItem, iSubItem, LVIR_LABEL, rcItem);
		rcText = rcItem;
		
		CSize size = pDC->GetTextExtent(strItemText);
		if(strItemText == _T(""))
		{
			size.cx = 41; 
		}
		
		//设置文本高亮矩形
		rcText.left += 4;
		rcText.right = rcText.left + size.cx + 6;
		if(rcText.right > rcItem.right)
		{
			rcText.right = rcItem.right;
		}
		
		COLORREF crOldTextColor = pDC->GetTextColor();

		//绘制项焦点/高亮效果
		if(m_bFocus)
		{
			
			if((m_iItem == iItem) && (m_iSubItem == iSubItem))
			{	
				if(m_bHighLight)
				{					
					pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
					pDC->FillSolidRect(&rcText, ::GetSysColor(COLOR_HIGHLIGHT));
				}
				pDC->DrawFocusRect(&rcText);
			}		
		}
		
		//绘制项文本
		rcItem.left += 6;
		pDC->DrawText(strItemText, &rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOCLIP);

		pDC->SetTextColor(crOldTextColor);
		*pResult = CDRF_SKIPDEFAULT;// We've painted everything.
	}	
}
コード例 #27
0
void CXTPSyntaxEditColorComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	CDC*  pDC       = CDC::FromHandle(lpDIS->hDC);
	UINT  itemState = lpDIS->itemState;
	UINT  itemID    = lpDIS->itemID;
	CRect rcItem    = lpDIS->rcItem;

	if (itemID == (UINT)-1)
	{
		return;
	}

	BOOL bDisabled = ((itemState & ODS_DISABLED) == ODS_DISABLED);
	BOOL bSelected = ((itemState & ODS_SELECTED) == ODS_SELECTED);
	BOOL bFocus    = ((itemState & ODS_FOCUS)    == ODS_FOCUS);

	// draw background.
	if (bDisabled)
	{
		pDC->SetTextColor(GetXtremeColor(COLOR_GRAYTEXT));
		pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
		pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_3DFACE));
	}
	else
	{
		if (bSelected)
		{
			pDC->SetTextColor(GetXtremeColor(COLOR_HIGHLIGHTTEXT));
			pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
			pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_HIGHLIGHT));
		}
		else
		{
			pDC->SetTextColor(GetXtremeColor(COLOR_WINDOWTEXT));
			pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
			pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_WINDOW));
		}

		// draw focus rectangle.
		if (bFocus)
		{
			pDC->DrawFocusRect(&rcItem);
		}
	}

	// determine the size of the color rectangle.
	CRect rColor(rcItem);
	rColor.DeflateRect(2,2);
	rColor.right = rColor.left + COLOR_ITEM_WIDTH;
	rColor.bottom = rColor.top + COLOR_ITEM_WIDTH;

	// draw color rectangle.
	pDC->FillSolidRect(rColor,
		bDisabled? GetXtremeColor(COLOR_3DFACE): (COLORREF)lpDIS->itemData);

	pDC->Draw3dRect(rColor,
		GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT),
		GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT));

	// determine the size of the text display.
	CRect rText(rColor);
	rText.top -= 2;
	rText.bottom = rText.top + (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE));
	rText.left = rText.right + 4;
	rText.right = rcItem.right;

	// draw text.
	CString csItemText;
	GetLBText(itemID, csItemText);
	if (!csItemText.IsEmpty())
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->DrawText(csItemText, rText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
	}
}
コード例 #28
0
//***************************************************************
void CColorListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
    if (!lpDrawItemStruct) return;
    IsCreated=TRUE;
	CDC*		pDC			= CDC::FromHandle(lpDrawItemStruct->hDC);
	CMyLParam*	pMyLParam	= GetMyLParam(lpDrawItemStruct->itemID);
	CRect		rcItem;

    if (!pMyLParam) return;
    int x=0;
    typedef enum {R_NOTHINGS=0, R_FOCUS, R_SELECT, R_NORMAL, R_SEL_NOFOCUS} redrawmode;
    redrawmode redraw=R_NORMAL;

	// Get item image and state info
	LV_ITEM lvi;
	lvi.mask = LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = lpDrawItemStruct->itemID;
	lvi.iSubItem = 0;
	lvi.stateMask = 0xFFFF;		// get all state flags
	GetItem(&lvi);

	BOOL bHighlight =   (   (lvi.state & LVIS_DROPHILITED)
                            ||
				            (
                                (lvi.state & LVIS_SELECTED) 
                                && 
                                (  ( GetFocus() == this )  || ( GetStyle() & LVS_SHOWSELALWAYS ) )
					        )
				        );

    BOOL bLostFocus=(GetFocus()!=this);


    if ( (lpDrawItemStruct->itemAction&ODA_FOCUS)==ODA_FOCUS)
    {   //the control gains or loses input focus
        if (bLostFocus) redraw=R_SEL_NOFOCUS;
        else
        if ((lvi.state&LVIS_FOCUSED)==LVIS_FOCUSED) redraw=R_FOCUS;
        else 
        {
            if (bHighlight) redraw=R_SELECT;
            else redraw=R_NORMAL;
        }
    }
    else
    if ((lpDrawItemStruct->itemAction&ODA_SELECT)==ODA_SELECT)
    {   //the selection status has changed
            if (bHighlight)
            {
                if (bLostFocus) redraw=R_SEL_NOFOCUS;
                 else redraw=R_SELECT;
            }
            else redraw=R_NORMAL;
    }
    else
    {   //redraw the item
        if (bLostFocus)
        {
            if (bHighlight) redraw=R_SEL_NOFOCUS;
             else
              redraw=R_NORMAL;
        }
        else 
        {
            if ((lvi.state&LVIS_FOCUSED)==LVIS_FOCUSED) redraw=R_FOCUS;
            else 
            {
                if (bHighlight) redraw=R_SELECT;
                 else redraw=R_NORMAL;
            }
        }
    }

    CPen       *pOldPen;
    CPen        pen;
    CGdiObject *pOldBrush;

    switch(redraw)
    {

        case R_FOCUS:
            rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE);
            pDC->FillSolidRect(rcItem, GetColorRef(DEF_SELBACKGROUND));
            pDC->SetTextColor(GetColorRef(DEF_SELTEXT));
            if (m_BigFocusRect)
            {
                pen.CreatePen( PS_DOT, 0, GetColorRef(DEF_SELTEXT) );
                pOldPen  =pDC->SelectObject(&pen);
                pOldBrush=pDC->SelectStockObject(NULL_BRUSH);
                pDC->Rectangle(rcItem);
                pDC->SelectObject(pOldPen);
                pDC->SelectObject(pOldBrush);
            }
            else pDC->DrawFocusRect(rcItem);
            for (x=0; x<m_columnSize; x++)
            {
                rcItem	= GetCellRect(lpDrawItemStruct->itemID, x, FALSE);
                pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER );
            }
            break;
        case R_SELECT:
            rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE);
            pDC->FillSolidRect(rcItem, GetColorRef(DEF_SELBACKGROUND));
            pDC->SetTextColor(GetColorRef(DEF_SELTEXT));
            for (x=0; x<m_columnSize; x++)
            {
                rcItem	= GetCellRect(lpDrawItemStruct->itemID, x, FALSE);
                pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
            }
            break;
        case R_SEL_NOFOCUS:
            rcItem=GetFullCellRect(lpDrawItemStruct->itemID, TRUE);
            pDC->FillSolidRect(rcItem, GetColorRef(DEF_DESELBACKGROUND));
            pDC->SetTextColor(pMyLParam->GetTextColor(DEF_DESELTEXT));
            pen.CreatePen( PS_DOT, 0, GetColorRef(DEF_DESELBACKGROUND) );
            pOldPen  =pDC->SelectObject(&pen);
            pOldBrush=pDC->SelectStockObject(NULL_BRUSH);
            if (!m_withSingleRect)
                pDC->Rectangle(rcItem);
            for (x=0; x<m_columnSize; x++)
            {
                rcItem	= GetCellRect(lpDrawItemStruct->itemID, x, FALSE);
                pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
            }
            pDC->SelectObject(pOldPen);
            pDC->SelectObject(pOldBrush);
            break;
        case R_NORMAL:
            for (x=0; x<m_columnSize; x++)
            {
	            rcItem	= GetCellRect(lpDrawItemStruct->itemID, x, TRUE);
                pDC->FillSolidRect(rcItem, pMyLParam->GetBackColor(x));
                pDC->SetTextColor(pMyLParam->GetTextColor(x));
                if (m_withSingleRect)
                {
                    pOldBrush=pDC->SelectStockObject(NULL_BRUSH);
                    pDC->Rectangle(rcItem);
                    pDC->SelectObject(pOldBrush);
                    
                }
                rcItem	= GetCellRect(lpDrawItemStruct->itemID, x, FALSE);
                pDC->DrawText(CListCtrl::GetItemText(lpDrawItemStruct->itemID,x), rcItem, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
            }
            break;
    }

    return;
}
コード例 #29
0
ファイル: Script Dlg.cpp プロジェクト: aolko/construct
void CClassListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	 //CRect members to store the position of the items
	CRect rItem;
	CDC* dc = CDC::FromHandle(lpDrawItemStruct->hDC);

	if ((int)lpDrawItemStruct->itemID < 0)
	{
		// If there are no elements in the CListBox
		// based on whether the list box has Focus  or not
		// draw the Focus Rect or Erase it,
		if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS))
		{
			dc->DrawFocusRect(&lpDrawItemStruct->rcItem);
		}
		else if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && !(lpDrawItemStruct->itemState & ODS_FOCUS))
		{
			dc->DrawFocusRect(&lpDrawItemStruct->rcItem);
		}
		   return;
	}


	// String to store the text
	CString strText;

	// Get the item text.
	GetText(lpDrawItemStruct->itemID, strText);

	//Initialize the CListBox Item's row size
	rItem = lpDrawItemStruct->rcItem;

	UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER;
	if (GetStyle() & LBS_USETABSTOPS)
	nFormat |= DT_EXPANDTABS;


	// If CListBox item selected, draw the highlight rectangle.
	// Or if CListBox item deselected, draw the rectangle using the window color.
	bool ItemSelected = (lpDrawItemStruct->itemState & ODS_SELECTED);
	bool ItemChecked = (lpDrawItemStruct->itemState & ODS_CHECKED);

	COLORREF crBG = RGB(255,255,255);
	COLORREF crText = RGB(0,0,255);

	if (ItemSelected)
	{
		crBG = crText;
		crText = 0xffffff;	
	}

	CBrush br(crBG);
	dc->FillRect(&rItem, &br);

	


	// If the CListBox item has focus, draw the focus rect.
	// If the item does not have focus, erase the focus rect.
	if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS))
	{
		dc->DrawFocusRect(&rItem);
	}
	else if ((lpDrawItemStruct->itemAction & ODA_FOCUS) && !(lpDrawItemStruct->itemState & ODS_FOCUS))
	{
		dc->DrawFocusRect(&rItem);
	}

	// To draw the Text in the CListBox set the background mode to Transparent.
	int iBkMode = dc->SetBkMode(TRANSPARENT);

	CFont font;
	font.CreatePointFont(100,"Courier New");

	dc->SetTextColor(crText);
	dc->SelectObject(&font);

	//Draw the Text
	dc->TextOut(rItem.left,rItem.top,strText);

}
コード例 #30
0
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDraw)
{try{
	int cCols = GetHeaderCtrl ()->GetItemCount ();
	CDC *dc = CDC::FromHandle (lpDraw->hDC);
	int xStart = lpDraw->rcItem.left;	
	CImageList *pImages = GetImageList (LVSIL_SMALL);
	BOOL bNeedBorder = FALSE;	

	

	CHeaderCtrl* pHdr = GetHeaderCtrl ();

	
	for (int i = 0; i < cCols; i++)
	{
		LVITEM item;
		TCHAR szItem [10000];
		int colWidth = GetColumnWidth (pHdr->OrderToIndex (i));

		xStart += 5;
		colWidth -= 5;

		item.iItem = lpDraw->itemID;
		item.iSubItem = i;
		item.pszText = szItem;
		item.cchTextMax = sizeof (szItem);
		item.mask = LVIF_IMAGE | LVIF_TEXT;

		GetItem (&item);

		
		if (i == 0)
		{
			item.state = GetItemState (lpDraw->itemID, LVIS_SELECTED|LVIS_FOCUSED);

			COLORREF clrBg = m_vInfo [lpDraw->itemID].clrBg;
			COLORREF clrText = m_vInfo [lpDraw->itemID].clrText;
	
			
			
			if (item.state & LVIS_FOCUSED)
				bNeedBorder = TRUE;

			if (item.state & LVIS_SELECTED)
			{
				clrBg = GetSysColor (COLOR_HIGHLIGHT);
				clrText = GetSysColor (COLOR_HIGHLIGHTTEXT);
				if (bNeedBorder == FALSE)
				{
					if (GetSelectionMark () == (int)lpDraw->itemID)
						bNeedBorder = TRUE;
				}
			}
		
			CBrush br;
			CPen pen;
			CBrush *oldBr;
			CPen *oldPen;

			if (RGBIsEqual (clrBg, clrText))
				clrText = (~clrText) & 0x00FFFFFF;

			dc->SetTextColor (clrText);

			br.CreateSolidBrush (clrBg);
			pen.CreatePen (PS_SOLID, 1, clrBg);

			oldBr = dc->SelectObject (&br);
			oldPen = dc->SelectObject (&pen);
			
			dc->Rectangle (&lpDraw->rcItem);

			
			if (m_bGrid)
			{
				CPen pen1 (PS_SOLID, 1, m_clrGrid);
				dc->SelectObject (&pen1);
				dc->MoveTo (lpDraw->rcItem.left, lpDraw->rcItem.bottom-1);
				dc->LineTo (lpDraw->rcItem.right, lpDraw->rcItem.bottom-1);
				dc->SelectObject (oldPen);
			}

			dc->SelectObject (oldBr);
			dc->SelectObject (oldPen);

			if (pImages)
			{
				

				CPoint pt;
				pt.x = xStart;
				pt.y = lpDraw->rcItem.top;
				if (m_pSelImages && (item.state & LVIS_SELECTED))
					m_pSelImages->Draw (dc, item.iImage, pt, ILD_TRANSPARENT);
				else
					pImages->Draw (dc, item.iImage, pt, ILD_TRANSPARENT);

				IMAGEINFO inf;
				pImages->GetImageInfo (item.iImage, &inf);

				xStart += inf.rcImage.right - inf.rcImage.left + 5;
				colWidth -= inf.rcImage.right - inf.rcImage.left + 5;
			}
		}

		if (*item.pszText)
		{
			

			int needX = GetStringWidth (item.pszText);
			BOOL bDrawText = TRUE;

			RECT rcText = lpDraw->rcItem;
			rcText.left = xStart;
			rcText.right = xStart + colWidth - 5;

			
			if (needX > colWidth-5)
			{
				RECT rc = rcText;
				int dx = GetStringWidth ("...");
				if (dx <= colWidth-5)
				{
					rc.left = rc.right - dx;
					dc->DrawText ("...", &rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
					rcText.right = rc.left - 5;
				}
				else
					bDrawText = FALSE;
			}

			if (bDrawText)
				dc->DrawText (szItem, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOPREFIX);
		}

		xStart += colWidth;

		
		if (m_bGrid)
		{
			
			CPen pen (PS_SOLID, 1, m_clrGrid);
			CPen *oldPen = dc->SelectObject (&pen);
			dc->MoveTo (xStart-1, lpDraw->rcItem.top);
			dc->LineTo (xStart-1, lpDraw->rcItem.bottom);
			dc->SelectObject (oldPen);
		}
	}

	if (bNeedBorder)
	{
		

		dc->SetTextColor (m_vInfo [lpDraw->itemID].clrText);
		RECT rc = lpDraw->rcItem;
		rc.bottom--; rc.right--;
		dc->DrawFocusRect (&rc);
	}

}catch (...){}
}