コード例 #1
1
void CEditDlgPolygon::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{

	int which = lpDrawItemStruct->itemID;

	CDC dc;
	dc.Attach( lpDrawItemStruct->hDC );

	if (which != -1) {
	    COLORREF clrBackground = GetSysColor(lpDrawItemStruct->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW);
		COLORREF oldBackground = dc.SetBkColor(clrBackground);

		// Draw the background box
		CBrush theBrush(clrBackground);
		CBrush *oldBrush = dc.SelectObject(&theBrush);
		CPen *oldPen = (CPen *)(dc.SelectStockObject(NULL_PEN));
		dc.Rectangle(&(lpDrawItemStruct->rcItem));

		CPen thePen(PenStyles[which],1,lpDrawItemStruct->itemState & ODS_SELECTED ? RGB(255,255,255) : RGB(0,0,0));
		dc.SelectObject(&thePen);
		int y = lpDrawItemStruct->rcItem.top + (lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top)/2;
		int width = (lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left)-6;

    	dc.MoveTo(3,y);
		dc.LineTo(width,y);

		// Restore the dc to it's old state
		dc.SelectObject(oldPen);
		dc.SelectObject(oldBrush);
		dc.SetBkColor(oldBackground);
	}


   // If the item has the focus, draw focus rectangle
   if (lpDrawItemStruct->itemState & ODS_FOCUS)
		DrawFocusRect(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem);

   dc.Detach();
	
	// DON'T: CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
コード例 #2
0
ファイル: FileEditCtrl.cpp プロジェクト: moodboom/Reusable
void CFileEditCtrl::DrawButton(int nButtonState)
{
	ASSERT (IsWindow(this));
	
	// if the control is disabled, ensure the button is drawn disabled
	if (GetStyle() & WS_DISABLED)
		nButtonState = BTN_DISABLED;

	// Draw the button in the specified state (Up, Down, or Disabled)
	CWindowDC DC(this);		// get the DC for drawing

	CBrush theBrush(GetSysColor(COLOR_3DFACE));		// the colour of the button background
	CBrush *pOldBrush = DC.SelectObject(&theBrush);

	if (nButtonState == BTN_DOWN)	// Draw button as down
	{
		// draw the border
		CPen thePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = DC.SelectObject(&thePen);
		DC.Rectangle(&m_rcButtonArea);
		DC.SelectObject(pOldPen);
		thePen.DeleteObject();

		// draw the dots
		DrawDots (&DC, GetSysColor(COLOR_BTNTEXT), 1);
	}
	else	// draw button as up
	{
		CPen thePen(PS_SOLID, 1, GetSysColor(COLOR_3DFACE));
		CPen *pOldPen = DC.SelectObject(&thePen);
		DC.Rectangle(&m_rcButtonArea);
		DC.SelectObject(pOldPen);
		thePen.DeleteObject();

		// draw the border
		DC.DrawEdge(&m_rcButtonArea, EDGE_RAISED, BF_RECT);

		// draw the dots
		if (nButtonState == BTN_DISABLED)
		{
			DrawDots (&DC, GetSysColor(COLOR_3DHILIGHT), 1);
			DrawDots (&DC, GetSysColor(COLOR_GRAYTEXT));
		}
		else if (nButtonState == BTN_UP)
			DrawDots (&DC, GetSysColor(COLOR_BTNTEXT));
		else
			ASSERT (FALSE);	// Invalid nButtonState
	}
	DC.SelectObject(pOldBrush);
	theBrush.DeleteObject();

	// update m_nButtonState
	m_nButtonState = nButtonState;
}
コード例 #3
0
ファイル: FileEditCtrl.cpp プロジェクト: moodboom/Reusable
void CFileEditCtrl::DrawDots(CDC *pDC, COLORREF CR, int nOffset /* = 0 */)
{
	// draw the dots on the button
	int width = m_rcButtonArea.Width();			// width of the button
	div_t divt = div (width, 4);
	int delta = divt.quot;						// space between dots
	int left = m_rcButtonArea.left + width / 2 - delta - (divt.rem ? 0 : 1); // left side of first dot
	width = width / 10;							// width and height of one dot
	int top = m_rcButtonArea.Height() / 2 - width / 2 + 1;	// top of dots
	left += nOffset;							// draw dots shifted? ( for button pressed )
	top += nOffset;
	// draw the dots
	if (width < 2)
	{
		pDC->SetPixel(left, top, CR);
		left += delta;
		pDC->SetPixel(left, top, CR);
		left += delta;
		pDC->SetPixel(left, top, CR);
	}
	else
	{
		CPen thePen(PS_SOLID, 1, CR);			// set the dot colour
		CPen *pOldPen = pDC->SelectObject(&thePen);
		CBrush theBrush(CR);
		CBrush *pOldBrush = pDC->SelectObject(&theBrush);
		pDC->Ellipse(left, top, left + width, top + width);
		left += delta;
		pDC->Ellipse(left, top, left + width, top + width);
		left += delta;
		pDC->Ellipse(left, top, left + width, top + width);
		pDC->SelectObject(pOldBrush);			// reset the DC
		theBrush.DeleteObject();
		pDC->SelectObject(pOldPen);
		thePen.DeleteObject();
	}
}