显示图片并将其存储在增强型图元文件中
本部分包含一个示例,演示如何创建图片以及将相应记录存储在图元文件中的过程。 该示例将图片绘制到显示器或将其存储在图元文件中。 如果提供了显示设备上下文句柄,它将使用各种 GDI 函数将图片绘制到屏幕。 如果提供了增强型图元文件设备上下文,则会在增强的图元文件中存储相同的图片。
void DrawOrStore(HWND hwnd, HDC hdcMeta, HDC hdcDisplay)
{
RECT rect;
HDC hDC;
int fnMapModeOld;
HBRUSH hbrOld;
// Draw it to the display DC or store it in the metafile device context.
if (hdcMeta)
hDC = hdcMeta;
else
hDC = hdcDisplay;
// Set the mapping mode in the device context.
fnMapModeOld = SetMapMode(hDC, MM_LOENGLISH);
// Find the midpoint of the client area.
GetClientRect(hwnd, (LPRECT)&rect);
DPtoLP(hDC, (LPPOINT)&rect, 2);
// Select a gray brush.
hbrOld = SelectObject(hDC, GetStockObject(GRAY_BRUSH));
// Draw a circle with a one inch radius.
Ellipse(hDC, (rect.right/2 - 100), (rect.bottom/2 + 100),
(rect.right/2 + 100), (rect.bottom/2 - 100));
// Perform additional drawing here.
// Set the device context back to its original state.
SetMapMode(hDC, fnMapModeOld);
SelectObject(hDC, hbrOld);
}