5 Wine doesn't have windowsx.h, so we use this
7 #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
9 /* Wine seems to need this */
15 BOOL FileIsPlaceable( LPCSTR szFileName );
16 HMETAFILE GetPlaceableMetaFile( LPCSTR szFileName );
21 int deltax = 0, deltay = 0;
22 int width = 0, height = 0;
25 BOOL FileOpen(HWND hWnd, char *fn)
27 OPENFILENAME ofn = { sizeof(OPENFILENAME),
28 0, NULL, "Metafiles\0*.wmf\0", NULL, 0, 0, NULL,
29 FN_LENGTH, NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
30 OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
33 return GetOpenFileName(&ofn);
37 LRESULT CALLBACK WndProc(HWND hwnd,
47 BeginPaint(hwnd, &ps);
48 SetMapMode(ps.hdc, MM_ANISOTROPIC);
49 SetViewportExt(ps.hdc, width, height);
50 SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
51 if(hmf) PlayMetaFile(ps.hdc, hmf);
57 case WM_COMMAND: /* message: command from application menu */
58 switch (GET_WM_COMMAND_ID(wparam,lparam))
61 MessageBox( hwnd , "Hello there world!", "Hello", MB_OK);
66 char filename[FN_LENGTH];
67 if (FileOpen(hwnd, filename)) {
68 isAldus = FileIsPlaceable(filename);
71 hmf = GetPlaceableMetaFile(filename);
73 MessageBox(hwnd, "This is an Aldus placeable metafile: I can't deal with those!",
78 hmf = GetMetaFile(filename);
79 GetClientRect(hwnd, &r);
80 width = r.right - r.left;
81 height = r.bottom - r.top;
83 InvalidateRect( hwnd, NULL, TRUE );
90 InvalidateRect( hwnd, NULL, TRUE );
94 InvalidateRect( hwnd, NULL, TRUE );
98 InvalidateRect( hwnd, NULL, TRUE );
102 InvalidateRect( hwnd, NULL, TRUE );
110 return DefWindowProc(hwnd, uMessage, wparam, lparam);
114 case WM_DESTROY: /* message: window being destroyed */
118 default: /* Passes it on if unproccessed */
119 return DefWindowProc(hwnd, uMessage, wparam, lparam);
124 BOOL FileIsPlaceable( LPCSTR szFileName )
130 if( (hInFile = OpenFile( szFileName, &inof, OF_READ ) ) == HFILE_ERROR )
133 if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
134 != sizeof(APMFILEHEADER) )
141 /* Is it placeable? */
142 return (apmh.key == APMHEADER_KEY);
145 /* this code doesn't work */
147 HMETAFILE GetPlaceableMetaFile( LPCSTR szFileName )
152 APMFILEHEADER APMHeader;
153 HMETAFILE hmf = NULL;
157 if( (fh = OpenFile( szFileName, &inof, OF_READ ) ) == HFILE_ERROR ) return NULL;
159 if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return NULL;
160 _llseek(fh, sizeof(APMFILEHEADER), 0);
161 printf("sizeof(APMFILEHEADER) %d\n", sizeof(APMFILEHEADER));
162 if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return NULL;
164 if (!(hData = GlobalAlloc(GHND, (mfHeader.mtSize * 2L)))) return NULL;
166 if (!(lpData = GlobalLock(hData)))
172 _llseek(fh, sizeof(APMFILEHEADER), 0);
173 if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
182 if (!(hmf = (HMETAFILE) SetMetaFileBits(hData))) return NULL;
185 width = APMHeader.bbox.right - APMHeader.bbox.left;
186 height = APMHeader.bbox.bottom - APMHeader.bbox.top;
188 printf("Ok! width %d height %d\n", width, height);