다음을 통해 공유


CDC::CreateCompatibleDC

지정한 장치와 호환 되는 메모리 디바이스 컨텍스트를 만드는 pDC.

BOOL CreateCompatibleDC( 
   CDC* pDC  
);

매개 변수

  • pDC
    장치 컨텍스트에 대 한 포인터입니다. 경우 pDC 는 NULL, 시스템 디스플레이와 호환 되는 메모리 디바이스 컨텍스트는 함수를 만듭니다.

반환 값

함수가 성공 하면 0이 아닌. 그렇지 않으면 0입니다.

설명

메모리 장치 컨텍스트 디스플레이 표면을 나타내는 메모리 블록입니다. 호환 장치의 실제 장치 표면의 복사 하기 전에 메모리에 이미지를 준비 하려면 사용할 수 있습니다.

메모리 장치 컨텍스트를 만들 때 GDI가 자동으로 1-1 주식 단색 비트맵을 선택 합니다. GDI 출력 함수는 비트맵 생성 되 고 해당 컨텍스트 안에 선택 하는 경우 메모리 디바이스 컨텍스트를 사용할 수 있습니다.

만이 함수를 사용 하 여 래스터 작업을 지 원하는 장치에 대해 호환 장치 컨텍스트를 만들 수 있습니다. 참조는 CDC::BitBlt 멤버 함수를 비트 블록 전송 장치 컨텍스트 간에 관련 된 정보. 장치 컨텍스트 래스터 작업을 지원 하는지 여부를 확인 하려면 참조는 RC_BITBLT 멤버 함수에서 래스터 기능 CDC::GetDeviceCaps.

예제

// This handler loads a bitmap from system resources, 
// centers it in the view, and uses BitBlt() to paint the bitmap 
// bits. 
void CDCView::DrawBitmap(CDC* pDC)
{
   // load IDB_BITMAP1 from our resources
   CBitmap bmp;
   if (bmp.LoadBitmap(IDB_BITMAP1))
   {
      // Get the size of the bitmap
      BITMAP bmpInfo;
      bmp.GetBitmap(&bmpInfo);

      // Create an in-memory DC compatible with the 
      // display DC we're using to paint
      CDC dcMemory;
      dcMemory.CreateCompatibleDC(pDC);

      // Select the bitmap into the in-memory DC
      CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

      // Find a centerpoint for the bitmap in the client area
      CRect rect;
      GetClientRect(&rect);
      int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
      int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

      // Copy the bits from the in-memory DC into the on- 
      // screen DC to actually do the painting. Use the centerpoint 
      // we computed for the target offset.
      pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 
         0, 0, SRCCOPY);

      dcMemory.SelectObject(pOldBitmap);
   }
   else
   {
      TRACE0("ERROR: Where's IDB_BITMAP1?\n");
   }
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CDC 클래스

계층 구조 차트

CDC::CDC

CDC::GetDeviceCaps

CreateCompatibleDC

CDC::BitBlt

CDC::CreateDC

CDC::CreateIC

CDC::DeleteDC