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( HWND hwnd
, 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, 0, "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 SetViewportExtEx(ps
.hdc
, width
, height
, NULL
);
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(hwnd
, 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
);
84 case IDM_SET_EXT_TO_WIN
:
87 GetClientRect(hwnd
, &r
);
88 width
= r
.right
- r
.left
;
89 height
= r
.bottom
- r
.top
;
90 InvalidateRect( hwnd
, NULL
, TRUE
);
97 InvalidateRect( hwnd
, NULL
, TRUE
);
101 InvalidateRect( hwnd
, NULL
, TRUE
);
105 InvalidateRect( hwnd
, NULL
, TRUE
);
109 InvalidateRect( hwnd
, NULL
, TRUE
);
117 return DefWindowProc(hwnd
, uMessage
, wparam
, lparam
);
121 case WM_DESTROY
: /* message: window being destroyed */
125 default: /* Passes it on if unproccessed */
126 return DefWindowProc(hwnd
, uMessage
, wparam
, lparam
);
131 BOOL
FileIsPlaceable( LPCSTR szFileName
)
137 if( (hInFile
= OpenFile( szFileName
, &inof
, OF_READ
) ) == HFILE_ERROR
)
140 if( _lread( hInFile
, &apmh
, sizeof(APMFILEHEADER
) )
141 != sizeof(APMFILEHEADER
) )
148 /* Is it placeable? */
149 return (apmh
.key
== APMHEADER_KEY
);
152 HMETAFILE
GetPlaceableMetaFile( HWND hwnd
, LPCSTR szFileName
)
156 APMFILEHEADER APMHeader
;
163 if( (fh
= OpenFile( szFileName
, &inof
, OF_READ
) ) == HFILE_ERROR
) return 0;
165 if (!_lread(fh
, (LPSTR
)&APMHeader
, sizeof(APMFILEHEADER
))) return 0;
166 _llseek(fh
, sizeof(APMFILEHEADER
), 0);
168 p
= (WORD
*) &APMHeader
;
172 if (checksum
!= APMHeader
.checksum
) {
174 sprintf(msg
, "Computed checksum %04x != stored checksum %04x\n",
175 checksum
, APMHeader
.checksum
);
176 MessageBox(hwnd
, msg
, "Checksum failed", MB_OK
);
180 if (!_lread(fh
, (LPSTR
)&mfHeader
, sizeof(METAHEADER
))) return 0;
182 if (!(lpData
= (LPSTR
) GlobalAlloc(GPTR
, (mfHeader
.mtSize
* 2L)))) return 0;
184 _llseek(fh
, sizeof(APMFILEHEADER
), 0);
185 if (!_lread(fh
, lpData
, (UINT
)(mfHeader
.mtSize
* 2L)))
193 if (!(hmf
= SetMetaFileBitsEx(mfHeader
.mtSize
*2, lpData
)))
197 width
= APMHeader
.bbox
.Right
- APMHeader
.bbox
.Left
;
198 height
= APMHeader
.bbox
.Bottom
- APMHeader
.bbox
.Top
;
200 /* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
201 width
= width
*96/APMHeader
.inch
;
202 height
= height
*96/APMHeader
.inch
;