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 */
16 BOOL FileIsPlaceable( LPCSTR szFileName );
17 HMETAFILE GetPlaceableMetaFile( LPCSTR szFileName );
22 int deltax = 0, deltay = 0;
23 int width = 0, height = 0;
26 BOOL FileOpen(HWND hWnd, char *fn)
28 OPENFILENAME ofn = { sizeof(OPENFILENAME),
29 0, NULL, "Metafiles\0*.wmf\0", NULL, 0, 0, NULL,
30 FN_LENGTH, NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
31 OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
34 return GetOpenFileName(&ofn);
38 LRESULT CALLBACK WndProc(HWND hwnd,
48 BeginPaint(hwnd, &ps);
49 SetMapMode(ps.hdc, MM_ANISOTROPIC);
50 SetViewportExt(ps.hdc, width, height);
51 SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
52 if(hmf) PlayMetaFile(ps.hdc, hmf);
58 case WM_COMMAND: /* message: command from application menu */
59 switch (GET_WM_COMMAND_ID(wparam,lparam))
62 MessageBox( hwnd , "Hello there world!", "Hello", MB_OK);
67 char filename[FN_LENGTH];
68 if (FileOpen(hwnd, filename)) {
69 isAldus = FileIsPlaceable(filename);
71 hmf = GetPlaceableMetaFile(filename);
74 hmf = GetMetaFile(filename);
75 GetClientRect(hwnd, &r);
76 width = r.right - r.left;
77 height = r.bottom - r.top;
79 InvalidateRect( hwnd, NULL, TRUE );
86 InvalidateRect( hwnd, NULL, TRUE );
90 InvalidateRect( hwnd, NULL, TRUE );
94 InvalidateRect( hwnd, NULL, TRUE );
98 InvalidateRect( hwnd, NULL, TRUE );
106 return DefWindowProc(hwnd, uMessage, wparam, lparam);
110 case WM_DESTROY: /* message: window being destroyed */
114 default: /* Passes it on if unproccessed */
115 return DefWindowProc(hwnd, uMessage, wparam, lparam);
120 BOOL FileIsPlaceable( LPCSTR szFileName )
126 if( (hInFile = OpenFile( szFileName, &inof, OF_READ ) ) == HFILE_ERROR )
129 if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
130 != sizeof(APMFILEHEADER) )
137 /* Is it placeable? */
138 return (apmh.key == APMHEADER_KEY);
141 HMETAFILE GetPlaceableMetaFile( LPCSTR szFileName )
145 APMFILEHEADER APMHeader;
152 if( (fh = OpenFile( szFileName, &inof, OF_READ ) ) == HFILE_ERROR ) return 0;
154 if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
155 _llseek(fh, sizeof(APMFILEHEADER), 0);
157 p = (WORD *) &APMHeader;
161 if (checksum != APMHeader.checksum) {
163 sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
164 checksum, APMHeader.checksum);
165 /* MessageBox(hwnd, msg, "Checksum failed", MB_OK); */
169 if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
171 if (!(lpData = GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
173 _llseek(fh, sizeof(APMFILEHEADER), 0);
174 if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
182 if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
186 width = APMHeader.bbox.right - APMHeader.bbox.left;
187 height = APMHeader.bbox.bottom - APMHeader.bbox.top;
189 /* printf("Ok! width %d height %d\n", width, height); */