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