2 * Copyright 1998 Douglas Ridgway
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 Wine doesn't have windowsx.h, so we use this
26 #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
28 /* Wine seems to need this */
34 BOOL FileIsPlaceable( LPCSTR szFileName );
35 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName );
40 int deltax = 0, deltay = 0;
41 int width = 0, height = 0;
44 BOOL FileOpen(HWND hWnd, char *fn)
46 OPENFILENAME ofn = { sizeof(OPENFILENAME),
47 0, 0, NULL, NULL, 0, 0, NULL,
48 FN_LENGTH, NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
49 OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
50 ofn.lpstrFilter = "Metafiles\0*.wmf\0";
53 return GetOpenFileName(&ofn);
57 LRESULT CALLBACK WndProc(HWND hwnd,
67 BeginPaint(hwnd, &ps);
68 SetMapMode(ps.hdc, MM_ANISOTROPIC);
69 SetViewportExtEx(ps.hdc, width, height, NULL);
70 SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
71 if(hmf) PlayMetaFile(ps.hdc, hmf);
77 case WM_COMMAND: /* message: command from application menu */
78 switch (GET_WM_COMMAND_ID(wparam,lparam))
81 MessageBox( hwnd , "Hello there world!", "Hello", MB_OK);
86 char filename[FN_LENGTH];
87 if (FileOpen(hwnd, filename)) {
88 isAldus = FileIsPlaceable(filename);
90 hmf = GetPlaceableMetaFile(hwnd, filename);
93 hmf = GetMetaFile(filename);
94 GetClientRect(hwnd, &r);
95 width = r.right - r.left;
96 height = r.bottom - r.top;
98 InvalidateRect( hwnd, NULL, TRUE );
103 case IDM_SET_EXT_TO_WIN:
106 GetClientRect(hwnd, &r);
107 width = r.right - r.left;
108 height = r.bottom - r.top;
109 InvalidateRect( hwnd, NULL, TRUE );
116 InvalidateRect( hwnd, NULL, TRUE );
120 InvalidateRect( hwnd, NULL, TRUE );
124 InvalidateRect( hwnd, NULL, TRUE );
128 InvalidateRect( hwnd, NULL, TRUE );
136 return DefWindowProc(hwnd, uMessage, wparam, lparam);
140 case WM_DESTROY: /* message: window being destroyed */
144 default: /* Passes it on if unproccessed */
145 return DefWindowProc(hwnd, uMessage, wparam, lparam);
150 BOOL FileIsPlaceable( LPCSTR szFileName )
155 if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
158 if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
159 != sizeof(APMFILEHEADER) )
166 /* Is it placeable? */
167 return (apmh.key == APMHEADER_KEY);
170 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
174 APMFILEHEADER APMHeader;
180 if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
182 if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
183 _llseek(fh, sizeof(APMFILEHEADER), 0);
185 p = (WORD *) &APMHeader;
189 if (checksum != APMHeader.checksum) {
191 sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
192 checksum, APMHeader.checksum);
193 MessageBox(hwnd, msg, "Checksum failed", MB_OK);
197 if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
199 if (!(lpData = (LPSTR) GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
201 _llseek(fh, sizeof(APMFILEHEADER), 0);
202 if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
204 GlobalFree((HGLOBAL)lpData);
210 if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
214 width = APMHeader.bbox.Right - APMHeader.bbox.Left;
215 height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;
217 /* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
218 width = width*96/APMHeader.inch;
219 height = height*96/APMHeader.inch;