Отображение рисунка и его сохранение в расширенном метафайлове
В этом разделе содержится пример, демонстрирующий создание рисунка и процесс хранения соответствующих записей в метафайле. В примере рисунок выводится на экран или сохраняется в метафайле. Если задан дескриптор контекста устройства отображения, он рисует рисунок на экране с помощью различных функций 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);
}