コード例 #1
0
ファイル: IATTDLG.CPP プロジェクト: jimmccurdy/ArchiveGit
BOOL CAttWorldNetServiceDialog::OnEraseBkgnd(CDC* pDC) 
{
	INHERITED::OnEraseBkgnd(pDC);

	if ((m_pDDB != NULL) && (m_pDDB->IsValid()))
	{
		BITMAP Bitmap;
									
		if (CBitmap::FromHandle(m_pDDB->GetBitmap())->GetObject(sizeof(Bitmap), &Bitmap) != 0)
		{
			CWnd* pWnd = GetDlgItem(IDC_ATTWORLDNETBMP);
			if (pWnd != NULL)
			{
				CRect crWindow;
				pWnd->GetWindowRect(crWindow);
				ScreenToClient(crWindow);
				CRect crBitmap(0, 0, Bitmap.bmWidth, Bitmap.bmHeight);
				crBitmap.OffsetRect(crWindow.left, crWindow.top);

	  			CPalette *pcpOld;
  				if ((pcpOld = pDC->SelectPalette(CPalette::FromHandle(m_pDDB->GetPalette()), FALSE)) != NULL)
				{
					pDC->RealizePalette();
					
					CDC cdcBitmap;
					if ((cdcBitmap.CreateCompatibleDC(pDC)) != NULL)
					{
						CBitmap *pcbmOld;
							
						if ((pcbmOld = cdcBitmap.SelectObject(CBitmap::FromHandle(m_pDDB->GetBitmap()))) != NULL)
						{
							pDC->BitBlt(
								crBitmap.left,
								crBitmap.top,
								crBitmap.Width(),
								crBitmap.Height(),
								&cdcBitmap,
								0,
								0,
								SRCCOPY);
									
							cdcBitmap.SelectObject(pcbmOld);
						}
					}
					pDC->SelectPalette(pcpOld, FALSE);
					pDC->RealizePalette();
				}
			}
		}
	}

	return TRUE;
}
コード例 #2
0
void CBitmapControl::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CRect crUpdate(&dc.m_ps.rcPaint);

	if (!crUpdate.IsRectEmpty())
	{
		if (LoadBitmapResource())
		{
			CRect crClient;
			GetClientRect(&crClient);
		
			CRect crBitmap(0, 0, (int)m_nBitmapWidth, (int)m_nBitmapHeight);
			CRect crDraw;
	
			if (m_dwStyle & SBS_SIZEBITMAP)
			{
				crDraw = crClient;
			}
			else
			{
				crDraw = crBitmap;
				crDraw.OffsetRect(crClient.left, crClient.top);
			}

			int nOldMapMode = dc.SetMapMode(MM_TEXT);

			CPalette* pOldPalette;
			CPalette* pCurrentPalette = CPalette::FromHandle(m_pDDB->GetPalette());

			if ((pOldPalette = dc.SelectPalette(pCurrentPalette, FALSE)) != NULL)
			{
				dc.RealizePalette();

				CDC cdcBitmap;

				if ((cdcBitmap.CreateCompatibleDC(&dc)) != NULL)
				{
					CPalette *pOldBitmapPalette;

					if ((pOldBitmapPalette = cdcBitmap.SelectPalette(pCurrentPalette, FALSE)) != NULL)
					{
						cdcBitmap.RealizePalette();
						cdcBitmap.SetMapMode(MM_TEXT);

						CBitmap *pOldBitmap;

						if ((pOldBitmap = cdcBitmap.SelectObject(CBitmap::FromHandle(m_pDDB->GetBitmap()))) != NULL)
						{
							int nOldStretchMode = dc.SetStretchBltMode(STRETCH_DELETESCANS);

							dc.StretchBlt(
								crDraw.left,
								crDraw.top,
								crDraw.Width(),
								crDraw.Height(),
								&cdcBitmap,
								0,
								0,
								m_nBitmapWidth,
								m_nBitmapHeight,
								SRCCOPY);
							
							dc.SetStretchBltMode(nOldStretchMode);
							cdcBitmap.SelectObject(pOldBitmap);
						}
						
						cdcBitmap.SelectPalette(pOldBitmapPalette, FALSE);
					}
				}

				dc.SelectPalette(pOldPalette, FALSE);
			}

			dc.SetMapMode(nOldMapMode);
		}
	}
}