次の方法で共有


CDC::CreateCompatibleDC

pDCによって指定されたデバイスと互換性のあるメモリ デバイス コンテキストを作成します。

BOOL CreateCompatibleDC(
   CDC* pDC 
);

パラメーター

  • pDC
    デバイス コンテキストへのポインター。pDC が nullの場合、関数はシステムの表示と互換性のあるメモリ デバイス コンテキストを作成します。

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。

解説

メモリ デバイス コンテキストは表示サーフェイスを表すメモリ ブロックです。これは、互換性のあるデバイスに、機器のサーフェイスにコピーする前に、メモリのイメージを用意するために使用できます。

メモリ デバイス コンテキストが作成されると、GDI は自動的にオブジェクトのモノクロ ビットマップの株式に 1 × 1 を選択します。GDI の出力関数は、メモリ デバイス コンテキストとそのコンテキストにビットマップが作成され、選択された場合にのみ使用できます。

この関数は、ラスター オペレーションをサポートするデバイスの互換性のあるデバイス コンテキストを作成するためにのみ使用できます。デバイス コンテキストとのビット ブロック転送に関する情報については CDC::BitBlt のメンバー関数に関するトピックを参照してください。デバイス コンテキストがラスター オペレーションをサポートするかどうかを調べるには、メンバー関数 CDC::GetDeviceCapsRC_BITBLT ラスターの機能を参照してください。

使用例

// 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