Affichage d’une image et stockage dans un métafichier amélioré
Cette section contient un exemple illustrant la création d’une image et le processus de stockage des enregistrements correspondants dans un métafichier. L’exemple dessine une image à l’écran ou la stocke dans un métafichier. Si un handle de contexte de périphérique d’affichage est donné, il dessine une image à l’écran à l’aide de différentes fonctions GDI. Si un contexte de périphérique de métafichier amélioré est donné, il stocke la même image dans le métafichier amélioré.
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);
}