CreateCompatibleDC

该函数创建一个与指定设备兼容的内存设备上下文环境(DC)。
基础资料
简介

函数功能

通过GetDc()获取的HDC直接与相关设备沟通,而本函数创建的DC,则是与内存中的一个表面相关联。

函数原型

HDC CreateCompatibleDC(HDC hdc);

vb定义:

Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long

参数

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. IfpDCisNULL, 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");

}

}

首页
科技
#贵族
最新入驻
贾科莫·普契尼
Caroline Lufkin
翁建宇
相关阅读
ReleaseDC
内容词条·2743人浏览
BeginPaint
内容词条·1246人浏览
CEdit
内容词条·4090人浏览
CList
内容词条·4358人浏览
GetDCEx
内容词条·6232人浏览
SetIndicators
内容词条·2844人浏览
  • 网站地图
  • |

Copyright 2023 fuwu029.com赣ICP备2022008914号-4