コード例 #1
0
ファイル: CSoundLight.cpp プロジェクト: ysangkok/pgpfone
static void 
MakeLightBitmap(CBitmap *bitmap, CPaintDC *dc, CRect *rect, COLORREF color)
{
	CBrush brush(dc->GetNearestColor(GetSysColor(COLOR_3DFACE)));
	CBrush colorBrush(dc->GetNearestColor(color));
	CPen pen(PS_SOLID, 1, dc->GetNearestColor(GetSysColor(COLOR_3DFACE)));
	CDC lightDC;
	CRect workRect;

	//Make the bitmap we'll work on:
	lightDC.CreateCompatibleDC(dc);
	bitmap->CreateCompatibleBitmap(dc,
							rect->Width(), 
							rect->Height());
	lightDC.SelectObject(bitmap);

	//The first step is to blank out the background
	lightDC.SelectObject(&brush);
	lightDC.SelectObject(&pen);

	lightDC.Rectangle(0, 0, rect->Width(), rect->Height());

	//Next, get a black pen and make a circle...
	pen.DeleteObject();
	pen.CreatePen(PS_SOLID, 1, dc->GetNearestColor(RGB(0, 0, 0)));
	lightDC.SelectObject(&pen);
	lightDC.Ellipse(rect);
	workRect = *rect;
	workRect.DeflateRect(LIGHT_WIDTH / 4, LIGHT_HEIGHT / 4);
	lightDC.Ellipse(workRect);

	//Last, fill it with the appropriate color:
	//Next, get a black pen and make a circle...
	lightDC.SelectObject(colorBrush);
	lightDC.FloodFill(LIGHT_WIDTH / 2, 
					  LIGHT_HEIGHT / 2, 
					  dc->GetNearestColor(RGB(0, 0, 0)));
}
コード例 #2
0
void CMultiLineListBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	CDC* pDC = CDC::FromHandle(lpDIS->hDC);

	COLORREF rColor = (COLORREF)lpDIS->itemData; // RGB in item data

	CString sLabel;
	GetText(lpDIS->itemID, sLabel);

	// item selected
	if ((lpDIS->itemState & ODS_SELECTED) &&
		(lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
	{
		// draw color box
		CBrush colorBrush(rColor);
		CRect colorRect = lpDIS->rcItem;

		// draw label background
		CBrush labelBrush(::GetSysColor(COLOR_HIGHLIGHT));
		CRect labelRect = lpDIS->rcItem;
		pDC->FillRect(&labelRect,&labelBrush);

		// draw label text
		COLORREF colorTextSave;
		COLORREF colorBkSave;

		colorTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		colorBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
		pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK );

		pDC->SetTextColor(colorTextSave);
		pDC->SetBkColor(colorBkSave);

		return;
	}

	// item brought into box
	if (lpDIS->itemAction & ODA_DRAWENTIRE)
	{
		CBrush brush(rColor);
		CRect rect = lpDIS->rcItem;
		pDC->SetBkColor(rColor);
		pDC->FillRect(&rect,&brush);
		pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK );

		return;
	}

	// item deselected
	if (!(lpDIS->itemState & ODS_SELECTED) &&
		(lpDIS->itemAction & ODA_SELECT))
	{
		CRect rect = lpDIS->rcItem;
		CBrush brush(rColor);
		pDC->SetBkColor(rColor);
		pDC->FillRect(&rect,&brush);
		pDC->DrawText( sLabel, -1, &lpDIS->rcItem, DT_WORDBREAK );

		return;
	}
}