Write a VC++ Program to Demonstrate MetaFiles.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc,hdcMeta;
static HMETAFILE hmf;
static int cxClient,cyClient;
HBRUSH hBrush;
int x,y;
switch (message)
{
case WM_CREATE:
hdcMeta=CreateMetaFile(NULL);
hBrush=CreateSolidBrush(RGB(0,0,255));
Rectangle(hdcMeta,0,0,100,100);
MoveToEx(hdcMeta,0,0,NULL);
LineTo(hdcMeta,100,100);
MoveToEx(hdcMeta,0,100,NULL);
LineTo(hdcMeta,100,0);
SelectObject(hdcMeta,hBrush);
Ellipse(hdcMeta,20,20,80,80);
hmf=CloseMetaFile(hdcMeta);
DeleteObject(hBrush);
return 0;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
SetMapMode(hdc,MM_ANISOTROPIC);
SetWindowExtEx(hdc,1000,1000,NULL);
SetViewportExtEx(hdc,cxClient,cyClient,NULL);
for(x=0;x<10;x++)
{
for(y=0;y<10;y++)
{
SetWindowOrgEx(hdc,-100*x,-100*y,NULL);
PlayMetaFile(hdc,hmf);
}
}
EndPaint(hWnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Comments
Post a Comment