为什么我需要保存句柄到一个旧的位图,而绘制与Win32 GDI
Why do I need to save handle to an old bitmap while drawing with Win32 GDI?
下面是switch在WndProc函数中的代码,我已经给出了一个例子:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// Create a system memory device context.
bmHDC = CreateCompatibleDC(hdc);
// Hook up the bitmap to the bmHDC.
oldBM = (HBITMAP)SelectObject(bmHDC, ghBitMap);
// Now copy the pixels from the bitmap bmHDC has selected
// to the pixels from the client area hdc has selected.
BitBlt(
hdc, // Destination DC.
0, // 'left' coordinate of destination rectangle.
0, // 'top' coordinate of destination rectangle.
bmWidth, // 'right' coordinate of destination rectangle.
bmHeight, // 'bottom' coordinate of destination rectangle.
bmHDC, // Bitmap source DC.
0, // 'left' coordinate of source rectangle.
0, // 'top' coordinate of source rectangle.
SRCCOPY); // Copy the source pixels directly
// to the destination pixels
// Select the originally loaded bitmap.
SelectObject(bmHDC, oldBM);
// Delete the system memory device context.
DeleteDC(bmHDC);
EndPaint(hWnd, &ps);
return 0;
我的问题是为什么有必要在oldBM中保存和恢复SelectObject()的返回值?
为什么有必要在oldBM中保存和恢复SelectObject()的返回值?
BeginPaint()
给您一个HDC
,其中已经选择了一个默认的HBITMAP
。然后用自己的HBITMAP
替换它。您没有分配原始的HBITMAP
,也不拥有它,BeginPaint()
分配了它。当您使用完HDC
后,必须恢复原来的HBITMAP
,以便EndPaint()
在破坏HDC
时可以释放它,否则它将被泄露。
相关文章:
- 如何在快板的屏幕中显示子位图的绘制?
- 尝试绘制矩形(位图)
- 使用C 绘制Linux并创建位图
- Allegro 5如何绘制缩放位图区域
- 另一个从剪贴板线程绘制位图
- 直接2D 加载和绘制位图
- 将用于绘制为位图的像素格式更改
- 位图未在 CFrameWnd 的 OnPaint 中绘制
- 如何在C++中绘制纹理/位图的区域
- 如何在启用Windows Aero主题时在标题栏上绘制位图图标
- GDI+:绘制位图时出现未处理的异常
- BitBlt颠倒绘制位图
- Adafruit gfx库绘制位图没有程序
- 从内存中绘制位图
- c++ MFC:绘制位图到CFrame
- 绘制到GDI+位图
- 如何在c++中绘制位图作为OpenGL纹理
- 直接在对话框中绘制位图
- 是否可以将Windows位图绘制到cairo表面
- 将 OpenGL 绘制到屏幕外的位图