1*c2c66affSColin Finck #include <windows.h>
2*c2c66affSColin Finck #include <stdio.h>
3*c2c66affSColin Finck #include <string.h>
4*c2c66affSColin Finck 
5*c2c66affSColin Finck //HFONT tf;
6*c2c66affSColin Finck HENHMETAFILE EnhMetafile;
7*c2c66affSColin Finck SIZE EnhMetafileSize;
8*c2c66affSColin Finck LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
9*c2c66affSColin Finck 
10*c2c66affSColin Finck int WINAPI
WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)11*c2c66affSColin Finck WinMain(HINSTANCE hInstance,
12*c2c66affSColin Finck 	HINSTANCE hPrevInstance,
13*c2c66affSColin Finck 	LPSTR lpszCmdLine,
14*c2c66affSColin Finck 	int nCmdShow)
15*c2c66affSColin Finck {
16*c2c66affSColin Finck   WNDCLASS wc;
17*c2c66affSColin Finck   MSG msg;
18*c2c66affSColin Finck   HWND hWnd;
19*c2c66affSColin Finck   ENHMETAHEADER emh;
20*c2c66affSColin Finck 
21*c2c66affSColin Finck   EnhMetafile = GetEnhMetaFile("test.emf");
22*c2c66affSColin Finck   if(!EnhMetafile)
23*c2c66affSColin Finck   {
24*c2c66affSColin Finck     fprintf(stderr, "GetEnhMetaFile failed (last error 0x%lX)\n",
25*c2c66affSColin Finck         GetLastError());
26*c2c66affSColin Finck     return(1);
27*c2c66affSColin Finck   }
28*c2c66affSColin Finck   GetEnhMetaFileHeader(EnhMetafile, sizeof(ENHMETAHEADER), &emh);
29*c2c66affSColin Finck   EnhMetafileSize.cx = emh.rclBounds.right - emh.rclBounds.left;
30*c2c66affSColin Finck   EnhMetafileSize.cy = emh.rclBounds.bottom - emh.rclBounds.top;
31*c2c66affSColin Finck 
32*c2c66affSColin Finck   wc.lpszClassName = "EnhMetaFileClass";
33*c2c66affSColin Finck   wc.lpfnWndProc = MainWndProc;
34*c2c66affSColin Finck   wc.style = CS_VREDRAW | CS_HREDRAW;
35*c2c66affSColin Finck   wc.hInstance = hInstance;
36*c2c66affSColin Finck   wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
37*c2c66affSColin Finck   wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
38*c2c66affSColin Finck   wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
39*c2c66affSColin Finck   wc.lpszMenuName = NULL;
40*c2c66affSColin Finck   wc.cbClsExtra = 0;
41*c2c66affSColin Finck   wc.cbWndExtra = 0;
42*c2c66affSColin Finck   if (RegisterClass(&wc) == 0)
43*c2c66affSColin Finck     {
44*c2c66affSColin Finck       DeleteEnhMetaFile(EnhMetafile);
45*c2c66affSColin Finck       fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
46*c2c66affSColin Finck 	      GetLastError());
47*c2c66affSColin Finck       return(1);
48*c2c66affSColin Finck     }
49*c2c66affSColin Finck 
50*c2c66affSColin Finck   hWnd = CreateWindow("EnhMetaFileClass",
51*c2c66affSColin Finck 		      "Enhanced Metafile test",
52*c2c66affSColin Finck 		      WS_OVERLAPPEDWINDOW,
53*c2c66affSColin Finck 		      0,
54*c2c66affSColin Finck 		      0,
55*c2c66affSColin Finck 		      EnhMetafileSize.cx + (2 * GetSystemMetrics(SM_CXSIZEFRAME)) + 2,
56*c2c66affSColin Finck 		      EnhMetafileSize.cy + (2 * GetSystemMetrics(SM_CYSIZEFRAME)) + GetSystemMetrics(SM_CYCAPTION) + 2,
57*c2c66affSColin Finck 		      NULL,
58*c2c66affSColin Finck 		      NULL,
59*c2c66affSColin Finck 		      hInstance,
60*c2c66affSColin Finck 		      NULL);
61*c2c66affSColin Finck   if (hWnd == NULL)
62*c2c66affSColin Finck     {
63*c2c66affSColin Finck       DeleteEnhMetaFile(EnhMetafile);
64*c2c66affSColin Finck       fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
65*c2c66affSColin Finck 	      GetLastError());
66*c2c66affSColin Finck       return(1);
67*c2c66affSColin Finck     }
68*c2c66affSColin Finck 
69*c2c66affSColin Finck 	//tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
70*c2c66affSColin Finck 	//	ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
71*c2c66affSColin Finck 	//	DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
72*c2c66affSColin Finck 
73*c2c66affSColin Finck   ShowWindow(hWnd, nCmdShow);
74*c2c66affSColin Finck 
75*c2c66affSColin Finck   while(GetMessage(&msg, NULL, 0, 0))
76*c2c66affSColin Finck   {
77*c2c66affSColin Finck     TranslateMessage(&msg);
78*c2c66affSColin Finck     DispatchMessage(&msg);
79*c2c66affSColin Finck   }
80*c2c66affSColin Finck 
81*c2c66affSColin Finck   DeleteEnhMetaFile(EnhMetafile);
82*c2c66affSColin Finck 
83*c2c66affSColin Finck   //DeleteObject(tf);
84*c2c66affSColin Finck   UnregisterClass("EnhMetaFileClass", hInstance);
85*c2c66affSColin Finck 
86*c2c66affSColin Finck   return msg.wParam;
87*c2c66affSColin Finck }
88*c2c66affSColin Finck 
MainWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)89*c2c66affSColin Finck LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
90*c2c66affSColin Finck {
91*c2c66affSColin Finck 	switch(msg)
92*c2c66affSColin Finck 	{
93*c2c66affSColin Finck 
94*c2c66affSColin Finck 	case WM_PAINT:
95*c2c66affSColin Finck 	{
96*c2c66affSColin Finck 	  PAINTSTRUCT ps;
97*c2c66affSColin Finck 	  RECT rc;
98*c2c66affSColin Finck       HDC hDC;
99*c2c66affSColin Finck       int bk;
100*c2c66affSColin Finck 
101*c2c66affSColin Finck 	  GetClientRect(hWnd, &rc);
102*c2c66affSColin Finck 	  hDC = BeginPaint(hWnd, &ps);
103*c2c66affSColin Finck 	  rc.left = (rc.right / 2) - (EnhMetafileSize.cx / 2);
104*c2c66affSColin Finck 	  rc.top = (rc.bottom / 2) - (EnhMetafileSize.cy / 2);
105*c2c66affSColin Finck 	  rc.right = rc.left + EnhMetafileSize.cx;
106*c2c66affSColin Finck 	  rc.bottom = rc.top + EnhMetafileSize.cy;
107*c2c66affSColin Finck 	  bk = SetBkMode(hDC, TRANSPARENT);
108*c2c66affSColin Finck 	  Rectangle(hDC, rc.left - 1, rc.top - 1, rc.right + 1, rc.bottom + 1);
109*c2c66affSColin Finck 	  SetBkMode(hDC, bk);
110*c2c66affSColin Finck 	  PlayEnhMetaFile(hDC, EnhMetafile, &rc);
111*c2c66affSColin Finck 	  EndPaint(hWnd, &ps);
112*c2c66affSColin Finck 	  break;
113*c2c66affSColin Finck     }
114*c2c66affSColin Finck 
115*c2c66affSColin Finck 	case WM_DESTROY:
116*c2c66affSColin Finck 	  PostQuitMessage(0);
117*c2c66affSColin Finck 	  break;
118*c2c66affSColin Finck 
119*c2c66affSColin Finck 	default:
120*c2c66affSColin Finck 	  return DefWindowProc(hWnd, msg, wParam, lParam);
121*c2c66affSColin Finck 	}
122*c2c66affSColin Finck 	return 0;
123*c2c66affSColin Finck }
124