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
, int fnsz
)
46 OPENFILENAME ofn
= { sizeof(OPENFILENAME
),
47 0, 0, NULL
, NULL
, 0, 0, NULL
,
48 fnsz
, NULL
, 0, NULL
, NULL
,
49 OFN_SHOWHELP
, 0, 0, NULL
, 0, NULL
};
50 ofn
.lpstrFilter
= "Metafiles\0*.wmf\0";
56 return GetOpenFileName(&ofn
);
60 LRESULT CALLBACK
WndProc(HWND hwnd
,
70 BeginPaint(hwnd
, &ps
);
71 SetMapMode(ps
.hdc
, MM_ANISOTROPIC
);
72 SetViewportExtEx(ps
.hdc
, width
, height
, NULL
);
73 SetViewportOrgEx(ps
.hdc
, deltax
, deltay
, NULL
);
74 if(hmf
) PlayMetaFile(ps
.hdc
, hmf
);
80 case WM_COMMAND
: /* message: command from application menu */
81 switch (GET_WM_COMMAND_ID(wparam
,lparam
))
84 MessageBox( hwnd
, "Hello there world!", "Hello", MB_OK
);
89 char filename
[FN_LENGTH
];
90 if (FileOpen(hwnd
, filename
, FN_LENGTH
)) {
91 isAldus
= FileIsPlaceable(filename
);
93 hmf
= GetPlaceableMetaFile(hwnd
, filename
);
96 hmf
= GetMetaFile(filename
);
97 GetClientRect(hwnd
, &r
);
98 width
= r
.right
- r
.left
;
99 height
= r
.bottom
- r
.top
;
101 InvalidateRect( hwnd
, NULL
, TRUE
);
106 case IDM_SET_EXT_TO_WIN
:
109 GetClientRect(hwnd
, &r
);
110 width
= r
.right
- r
.left
;
111 height
= r
.bottom
- r
.top
;
112 InvalidateRect( hwnd
, NULL
, TRUE
);
119 InvalidateRect( hwnd
, NULL
, TRUE
);
123 InvalidateRect( hwnd
, NULL
, TRUE
);
127 InvalidateRect( hwnd
, NULL
, TRUE
);
131 InvalidateRect( hwnd
, NULL
, TRUE
);
139 return DefWindowProc(hwnd
, uMessage
, wparam
, lparam
);
143 case WM_DESTROY
: /* message: window being destroyed */
147 default: /* Passes it on if unprocessed */
148 return DefWindowProc(hwnd
, uMessage
, wparam
, lparam
);
153 BOOL
FileIsPlaceable( LPCSTR szFileName
)
158 if( (hInFile
= _lopen( szFileName
, OF_READ
) ) == HFILE_ERROR
)
161 if( _lread( hInFile
, &apmh
, sizeof(APMFILEHEADER
) )
162 != sizeof(APMFILEHEADER
) )
169 /* Is it placeable? */
170 return (apmh
.key
== APMHEADER_KEY
);
173 HMETAFILE
GetPlaceableMetaFile( HWND hwnd
, LPCSTR szFileName
)
177 APMFILEHEADER APMHeader
;
183 if( (fh
= _lopen( szFileName
, OF_READ
) ) == HFILE_ERROR
) return 0;
185 if (!_lread(fh
, (LPSTR
)&APMHeader
, sizeof(APMFILEHEADER
))) return 0;
186 _llseek(fh
, sizeof(APMFILEHEADER
), 0);
188 p
= (WORD
*) &APMHeader
;
192 if (checksum
!= APMHeader
.checksum
) {
194 sprintf(msg
, "Computed checksum %04x != stored checksum %04x\n",
195 checksum
, APMHeader
.checksum
);
196 MessageBox(hwnd
, msg
, "Checksum failed", MB_OK
);
200 if (!_lread(fh
, (LPSTR
)&mfHeader
, sizeof(METAHEADER
))) return 0;
202 if (!(lpData
= (LPSTR
) GlobalAlloc(GPTR
, (mfHeader
.mtSize
* 2L)))) return 0;
204 _llseek(fh
, sizeof(APMFILEHEADER
), 0);
205 if (!_lread(fh
, lpData
, (UINT
)(mfHeader
.mtSize
* 2L)))
207 GlobalFree((HGLOBAL
)lpData
);
213 if (!(hmf
= SetMetaFileBitsEx(mfHeader
.mtSize
*2, lpData
)))
217 width
= APMHeader
.bbox
.Right
- APMHeader
.bbox
.Left
;
218 height
= APMHeader
.bbox
.Bottom
- APMHeader
.bbox
.Top
;
220 /* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
221 width
= width
*96/APMHeader
.inch
;
222 height
= height
*96/APMHeader
.inch
;