只能选入到内存DC吗?hDc选入一个hBmp,然后DeleteDC hDc
或者
hDc选入一个hBmp,然后DeleteObjecthBmp
行不行
或者
hDc选入一个hBmp,然后DeleteObjecthBmp
行不行
解决方案 »
- CPropertyPage的OnApply怎样通知它的Sheet?
- 帮我解释下这段代码的意思~~~~~~~~关于BITMAP底层操作
- 我想从word, ppt, excel中把文档的内容取出来该怎么办呀?
- 关于区域大小的计算,GetClientRect使用问题!
- 内存分配问题.高手来看看吧(set_new_handler)
- WNDCLASS 问题
- 关于IE前进、后退控制的问题。欢迎讨论!
- 有请诸位,新手求教——我能多久学会COM,DCOM
- CPaintDC透明画刷设置成功,但全局函数下的透明画刷设置不成功
- NURBS曲线反求控制顶点
- 在标签中没有显示图标,如何解决?
- 100分VC简单字串问题???
CDC dcMemory;
CDC *pDC = GetDC(); bmp.CreateCompatibleBitmap(pDC,16,16);
dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = (CBitmap* )dcMemory.SelectObject(&bmp);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo); // Find a center point 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 device context to the on-
// screen device context to do the painting. Use the computed center
// point for the target offset.
// pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
// 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); ReleaseDC(pDC);
In general, do not call this function; the destructor will do it for you. The DeleteDC member function deletes the Windows device contexts that are associated with m_hDC in the current CDC object. If this CDC object is the last active device context for a given device, the device is notified and all storage and system resources used by the device are released. An application should not call DeleteDC if objects have been selected into the device context. Objects must first be selected out of the device context before it it is deleted. An application must not delete a device context whose handle was obtained by calling CWnd::GetDC. Instead, it must call CWnd::ReleaseDC to free the device context. The CClientDC and CWindowDC classes are provided to wrap this functionality. The DeleteDC function is generally used to delete device contexts created with CreateDC, CreateIC, or CreateCompatibleDC.
1、GDI对象的资源释放,如下:
CBitmap *pOldBitmap = pDC->SelectObject(pBitmap);
......
pDC->SelectObject(pOldBitmap); //将原先的bitmap选入DC,有时也可以不用保存原来的GDI对象指针,直接用SelectObject()选入系统GDI对象就行。当然如果在GDI对象删除之前DC对象就已经被删除了,那就不需要将GDI对象调出设备环境了。
2、DC对象的资源释放,
pDC = GetDC();
.....
ReleaseDC(pDC); //用GetDC()得到的DC一定要用ReleaseDC()释放 而像:
void DrawXY()
{
CClientDC dc; //对于在堆栈上建立的DC对象,则在所在的函数运行完后自动删除。
....
}
个人观点,不知是否正确。
The DeleteDC member function deletes the Windows device contexts that are associated with m_hDC in the current CDC object. If this CDC object is the last active device context for a given device, the device is notified and all storage and system resources used by the device are released.
这不是讲的很清楚了吗?
An application should not call DeleteDC if objects have been selected into the device context. Objects must first be selected out of the device context before it it is deleted.
请先选出object再DeleteDCAn application must not delete a device context whose handle was obtained by calling CWnd::GetDC. Instead, it must call CWnd::ReleaseDC to free the device context. The CClientDC and CWindowDC classes are provided to wrap this functionality. The DeleteDC function is generally used to delete device contexts created with CreateDC, CreateIC, or CreateCompatibleDC.
也就是说DeleteDC请用在内存DC上
hOldBmp=SelectObject(hDc,hNewBmp)
...
SelectObject(hOldBmp)但是hOldBmp的值是0x0185000f,不知道是什么?上面第一段话好像有点不对,创建一个hDcMem,不就包含了默认了对象了吗?