Compartilhar via


Exibindo uma imagem e armazenando-a em um metarquivo aprimorado

Esta seção contém um exemplo que demonstra a criação de uma imagem e o processo de armazenamento dos registros correspondentes em um metarquivo. O exemplo desenha uma imagem para a exibição ou a armazena em um metarquivo. Se um identificador de contexto do dispositivo de exibição for fornecido, ele desenhará uma imagem para a tela usando várias funções GDI. Se um contexto de dispositivo de metafile aprimorado for fornecido, ele armazenará a mesma imagem no metarquivo aprimorado.

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); 
}