当前位置:首页 科普知识 CreateCompatibleDC

CreateCompatibleDC

发布时间:2023-09-14 00:54:45

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

CreateCompatibleDC介绍

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

CreateCompatibleDC

CreateCompatibleDC函数功能

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

CreateCompatibleDC函数原型

HDC CreateCompatibleDC(HDC hdc);

vb定义:

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

CreateCompatibleDC参数

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。

Creates a memory device context that is compatible with the device specified bypDC.

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 theRC_BITBLTraster capability in the member functionCDC::GetDeviceCaps.

Example:

// This handler loads a bitmap from system resources,

CreateCompatibleDC

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

CreateCompatibleDC

{

TRACE0("ERROR: Where's IDB_BITMAP1?n");

}

}

温馨提示:
本文【CreateCompatibleDC】由作者 爱百科 转载提供。 该文观点仅代表作者本人, 自学教育网 信息发布平台,仅提供信息存储空间服务, 若存在侵权问题,请及时联系管理员或作者进行删除。
(c)2008-2025 自学教育网 All Rights Reserved 汕头市灵创科技有限公司
粤ICP备2024240640号-6