CreateCompatibleDC类似GetDC,但只是表面关联

CreateCompatibleDC编辑

本词条缺少 概述信息栏名片图,补充相关内容使词条更完整,还能快速升级,赶紧来 编辑吧!

1函数功能编辑

该函数创建一个与指定设备兼容的内存 设备上下文环境(DC)。通过GetDc()获取的HDC直接与相关设备沟通,而本函数创建的DC,则是与内存中的一个表面相关联。

2函数原型编辑

HDC CreateCompatibleDC(HDC hdc);
vb定义:
Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long

3参数编辑

hdc:现有 设备上下文环境的句柄,如果该 句柄NULL,该函数创建一个与 应用程序的当前显示器兼容的内存设备上下文环境。
返回值:如果成功,则返回内存 设备上下文环境的句柄;如果失败,则返回值为NULL。
Windows NT:若想获得更多 错误信息,请调用GetLastError函数。
注释:内存 设备上下文环境是仅在内存中存在的设备上下文环境,当内存设备上下文环境被创建时,它的显示界面是标准的一个单色像素宽和一个单色像素高,在一个 应用程序可以使用内存设备上下文环境进行绘图操作之前,它必须选择一个高和宽都正确的位图到设备上下文环境中,这可以通过使用CreateCompatibleBitmap函数指定高、宽和色彩组合以满足 函数调用的需要。
当一个内存 设备上下文环境创建时,所有的特性都设为 缺省值,内存设备上下文环境作为一个普通的设备上下文环境使用,当然也可以设置这些特性为非缺省值,得到它的特性的当前设置,为它选择 画笔,刷子和区域。
CreateCompatibleDc函数只适用于支持光栅操作的设备, 应用程序可以通过调用GetDeviceCaps函数来确定一个设备是否支持这些操作。
当不再需要内存 设备上下文环境时,可调用DeleteDc函数删除它。
ICM:如果通过该函数的hdc参数传送给该函数 设备上下文环境(Dc)对于独立颜色管理(ICM)是能用的,则该函数创建的设备上下文环境(Dc)是ICM能用的,资源和目标颜色间隔是在Dc中定义。
速查: Windows NT:3.1及以上版本;Windows:95及以上版本; Windows CE:1.0及以上版本; 头文件:wingdi.h; 库文件:gdi32.lib。
[From MSDN]
Creates a memory device context that is compatible with the device specified by pDC.
BOOL CreateCompatibleDC(
  CDC* pDC 
  );
Parameter:
  • pDC
  • A pointer to a device context. If pDCis NULL, the function creates a memory device context that is compatible with the system display.
Return Value:
Nonzero if the function is successful; otherwise 0.
Remark:
A memory device context is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.
This function can only be used to create compatible device contexts for devices that support raster operations. See theCDC::BitBltmember function for information regarding bit-block transfers between device contexts. To determine whether a device context supports raster operations, see the RC_BITBLTraster capability in the member function CDC::GetDeviceCaps.
Example:
// 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");
  }
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值