예제 #1
0
void DrawDisabledButton(TDC& dc, const TRect& rc)
{
  // create a monochrome memory DC
  //
  TMemoryDC ddc;
  TBitmap bmp(ddc, rc.Width(), rc.Height());
  ddc.SelectObject(bmp);

  // build a mask
  //
  ddc.PatBlt(0, 0, rc.Width(), rc.Height(), WHITENESS);
  dc.SetBkColor(TColor::Sys3dFace);
  ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
  dc.SetBkColor(TColor::Sys3dHilight);
  ddc.BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCPAINT);

  // Copy the image from the toolbar into the memory DC
  // and draw it (grayed) back into the toolbar.
  //
  dc.FillRect(rc, TBrush(TColor::Sys3dFace));
  dc.SetBkColor(RGB(0, 0, 0));
  dc.SetTextColor(RGB(255, 255, 255));
  TBrush brShadow(TColor::Sys3dShadow);
  TBrush brHilight(TColor::Sys3dHilight);
  dc.SelectObject(brHilight);
  dc.BitBlt(rc.left+1, rc.top+1, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L);
  dc.SelectObject(brShadow);
  dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), ddc, 0, 0, 0x00E20746L);

  // reset DCs
  //
  dc.RestoreBrush();
  dc.RestoreBrush();
  ddc.RestoreBitmap();
}
예제 #2
0
void AFXAPI AfxGetGrayBitmap(const CBitmap &rSrc, CBitmap *pDest, COLORREF crBackground)
{
	ASSERT(pDest);
	ASSERT_KINDOF(CBitmap, pDest);

	BITMAP bm;
	CDC dcMem, dcMask;
	COLORREF cr;
	CBitmap bmpMask, *pOldMask, *pOldMem;
	const DWORD	CP_ROP = 0xE20746;
	CBrush brHighLight(::GetSysColor(COLOR_3DHIGHLIGHT)),
		brShadow(::GetSysColor(COLOR_3DSHADOW)), *pbr;

	if(dcMem.CreateCompatibleDC(NULL) &&
		dcMask.CreateCompatibleDC(NULL))
	{
		const_cast<CBitmap &>(rSrc).GetBitmap(&bm);
		pDest->DeleteObject();
		if(pDest->CreateBitmap(bm.bmWidth, bm.bmHeight, bm.bmPlanes, bm.bmBitsPixel, NULL) &&
			bmpMask.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL))
		{
			pOldMem = dcMem.SelectObject(const_cast<CBitmap *>(&rSrc));
			pOldMask = dcMask.SelectObject(&bmpMask);

			ASSERT(pOldMem && pOldMask);
			if(!pOldMem || !pOldMask)
				return;

			// Make the upper left corner pixel the "transparent" pixel
			cr = dcMem.SetBkColor(dcMem.GetPixel(0, 0));
			dcMask.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
			// Make white pixels transparent too
			dcMem.SetBkColor(RGB(255, 255, 255));
			dcMask.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, NOTSRCERASE);

			if(dcMem.SelectObject(pDest))
			{
				dcMem.FillSolidRect(0, 0, bm.bmWidth, bm.bmHeight, crBackground);

				dcMem.SetBkColor(RGB(255, 255, 255));

				pbr = dcMem.SelectObject(&brHighLight);
				dcMem.BitBlt(1, 1, bm.bmWidth, bm.bmHeight, &dcMask, 0, 0, CP_ROP);

				dcMem.SelectObject(&brShadow);
				dcMem.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMask, 0, 0, CP_ROP);

				dcMem.SelectObject(pbr);

				dcMem.SetBkColor(cr);
			}
			dcMask.SelectObject(pOldMask);
			dcMem.SelectObject(pOldMem);
		}
	}
}
예제 #3
0
void AFXAPI AfxDrawGrayBitmap(CDC *pDC, int x, int y, const CBitmap &rSrc, COLORREF crBackground)
{
	ASSERT(pDC);
	ASSERT_KINDOF(CDC, pDC);

	BITMAP bm;
	CDC dcMem, dcMask;
	COLORREF cr;
	CBitmap bmpMask, *pOldMask, *pOldMem;
	const DWORD	CP_ROP = 0xE20746;
	CBrush brHighLight(::GetSysColor(COLOR_3DHIGHLIGHT)),
		brShadow(::GetSysColor(COLOR_3DSHADOW)), *pbr;

	if(dcMem.CreateCompatibleDC(pDC) &&
		dcMask.CreateCompatibleDC(pDC) &&
		const_cast<CBitmap &>(rSrc).GetBitmap(&bm) &&
		bmpMask.CreateBitmap(bm.bmWidth, bm.bmHeight, 1, 1, NULL))
	{
		pOldMem = dcMem.SelectObject(const_cast<CBitmap *>(&rSrc));
		pOldMask = dcMask.SelectObject(&bmpMask);

		ASSERT(pOldMem && pOldMask);
		if(!pOldMem || !pOldMask)
			return;

		cr = dcMem.SetBkColor(dcMem.GetPixel(0, 0));
		dcMask.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, SRCCOPY);
		dcMem.SetBkColor(RGB(255, 255, 255));
		dcMask.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, NOTSRCERASE);

		pDC->FillSolidRect(x, y, bm.bmWidth, bm.bmHeight, crBackground);

		pDC->SetBkColor(RGB(255, 255, 255));

		pbr = pDC->SelectObject(&brHighLight);
		pDC->BitBlt(x + 1, y + 1, bm.bmWidth, bm.bmHeight, &dcMask, 0, 0, CP_ROP);

		pDC->SelectObject(&brShadow);
		pDC->BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcMask, 0, 0, CP_ROP);

		pDC->SelectObject(pbr);

		pDC->SetBkColor(cr);
		dcMask.SelectObject(pOldMask);
	}
}