1 | #define INCL_GPI
|
---|
2 | #define INCL_PM
|
---|
3 | #define INCL_MMIOOS2
|
---|
4 | #include <os2.h>
|
---|
5 | #include <stdio.h>
|
---|
6 | #include <stdlib.h>
|
---|
7 | #include <string.h>
|
---|
8 | //#include "os2me.h"
|
---|
9 | #include "mmioos2.h"
|
---|
10 |
|
---|
11 | #include "pmdaytip.h"
|
---|
12 | HAB hab;
|
---|
13 |
|
---|
14 | HBITMAP hBitmap;
|
---|
15 |
|
---|
16 | char text[200];
|
---|
17 |
|
---|
18 | HBITMAP loadBitmap ( PSZ pszFileName,
|
---|
19 | ULONG ulWidth,
|
---|
20 | ULONG ulHeight,
|
---|
21 | BOOL* pbQuitEarly)
|
---|
22 | {
|
---|
23 | HBITMAP hbm;
|
---|
24 | MMIOINFO mmioinfo;
|
---|
25 | MMFORMATINFO mmFormatInfo;
|
---|
26 | HMMIO hmmio;
|
---|
27 | ULONG ulImageHeaderLength;
|
---|
28 | MMIMAGEHEADER mmImgHdr;
|
---|
29 | ULONG ulBytesRead;
|
---|
30 | ULONG dwNumRowBytes;
|
---|
31 | PBYTE pRowBuffer;
|
---|
32 | ULONG dwRowCount;
|
---|
33 | SIZEL ImageSize;
|
---|
34 | ULONG dwHeight, dwWidth;
|
---|
35 | SHORT wBitCount;
|
---|
36 | FOURCC fccStorageSystem;
|
---|
37 | ULONG dwPadBytes;
|
---|
38 | ULONG dwRowBits;
|
---|
39 | ULONG ulReturnCode;
|
---|
40 | ULONG dwReturnCode;
|
---|
41 | HBITMAP hbReturnCode;
|
---|
42 | LONG lReturnCode;
|
---|
43 | FOURCC fccIOProc;
|
---|
44 | HDC hdc;
|
---|
45 | HPS hps;
|
---|
46 | HAB hab=WinQueryAnchorBlock(HWND_DESKTOP);
|
---|
47 |
|
---|
48 | ulReturnCode = mmioIdentifyFile ( pszFileName,
|
---|
49 | 0L,
|
---|
50 | &mmFormatInfo,
|
---|
51 | &fccStorageSystem,
|
---|
52 | 0L,
|
---|
53 | 0L);
|
---|
54 | /*
|
---|
55 | * If this file was NOT identified, then this function won't
|
---|
56 | * work, so return an error by indicating an empty bitmap.
|
---|
57 | */
|
---|
58 | if ( ulReturnCode == MMIO_ERROR )
|
---|
59 | {
|
---|
60 | return (0L);
|
---|
61 | }
|
---|
62 | /*
|
---|
63 | * If mmioIdentifyFile did not find a custom-written IO proc which
|
---|
64 | * can understand the image file, then it will return the DOS IO Proc
|
---|
65 | * info because the image file IS a DOS file.
|
---|
66 | */
|
---|
67 | if( mmFormatInfo.fccIOProc == FOURCC_DOS )
|
---|
68 | {
|
---|
69 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
70 | "Image file could not be interpreted by any permanently or temporarily installed IO procedures.",
|
---|
71 | "Open Image File",
|
---|
72 | (HMODULE) NULL,
|
---|
73 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
74 | MB_ERROR );
|
---|
75 | return ( 0L );
|
---|
76 | }
|
---|
77 | /*
|
---|
78 | * Ensure this is an IMAGE IOproc, and that it can read
|
---|
79 | * translated data
|
---|
80 | */
|
---|
81 | if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
|
---|
82 | ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
|
---|
83 | {
|
---|
84 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
85 | "No IMAGE IO Procedures exist which can translate the data in the image file specified.",
|
---|
86 | "Open Image File",
|
---|
87 | (HMODULE) NULL,
|
---|
88 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
89 | MB_ERROR );
|
---|
90 | return (0L);
|
---|
91 | }
|
---|
92 | else
|
---|
93 | {
|
---|
94 | fccIOProc = mmFormatInfo.fccIOProc;
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* Clear out and initialize mminfo structure */
|
---|
98 | memset ( &mmioinfo, 0L, sizeof ( MMIOINFO ) );
|
---|
99 | mmioinfo.fccIOProc = fccIOProc;
|
---|
100 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
---|
101 | hmmio = mmioOpen ( (PSZ) pszFileName,
|
---|
102 | &mmioinfo,
|
---|
103 | MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
|
---|
104 | if ( ! hmmio )
|
---|
105 | {
|
---|
106 | // If file could not be opened, return with error
|
---|
107 | return (0L);
|
---|
108 | }
|
---|
109 |
|
---|
110 | dwReturnCode = mmioQueryHeaderLength ( hmmio,
|
---|
111 | (PLONG)&ulImageHeaderLength,
|
---|
112 | 0L,
|
---|
113 | 0L);
|
---|
114 | if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
|
---|
115 | {
|
---|
116 | /* We have a problem.....possibly incompatible versions */
|
---|
117 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
118 | return (0L);
|
---|
119 | }
|
---|
120 |
|
---|
121 | ulReturnCode = mmioGetHeader ( hmmio,
|
---|
122 | &mmImgHdr,
|
---|
123 | (LONG) sizeof ( MMIMAGEHEADER ),
|
---|
124 | (PLONG)&ulBytesRead,
|
---|
125 | 0L,
|
---|
126 | 0L);
|
---|
127 |
|
---|
128 | if ( ulReturnCode != MMIO_SUCCESS )
|
---|
129 | {
|
---|
130 | /* Header unavailable */
|
---|
131 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
132 | return (0L);
|
---|
133 | }
|
---|
134 |
|
---|
135 | /*
|
---|
136 | * Determine the number of bytes required, per row.
|
---|
137 | * PLANES MUST ALWAYS BE = 1
|
---|
138 | */
|
---|
139 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
---|
140 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
---|
141 | wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
142 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
---|
143 | dwNumRowBytes = dwRowBits >> 3;
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * Account for odd bits used in 1bpp or 4bpp images that are
|
---|
147 | * NOT on byte boundaries.
|
---|
148 | */
|
---|
149 | if ( dwRowBits % 8 )
|
---|
150 | {
|
---|
151 | dwNumRowBytes++;
|
---|
152 | }
|
---|
153 | /*
|
---|
154 | * Ensure the row length in bytes accounts for byte padding.
|
---|
155 | * All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
|
---|
156 | * The data FROM an IOProc should always appear in this form.
|
---|
157 | */
|
---|
158 | dwPadBytes = ( dwNumRowBytes % 4 );
|
---|
159 | if ( dwPadBytes )
|
---|
160 | {
|
---|
161 | dwNumRowBytes += 4 - dwPadBytes;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* Allocate space for ONE row of pels */
|
---|
165 | if ( DosAllocMem( (PPVOID)&pRowBuffer,
|
---|
166 | (ULONG)dwNumRowBytes,
|
---|
167 | fALLOC))
|
---|
168 | {
|
---|
169 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
170 | return(0L);
|
---|
171 | }
|
---|
172 |
|
---|
173 | /* Create a device context */
|
---|
174 | hdc=DevOpenDC(hab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
|
---|
175 | if(hdc==NULLHANDLE)
|
---|
176 | {
|
---|
177 | DosFreeMem(pRowBuffer);
|
---|
178 | mmioClose (hmmio, 0L);
|
---|
179 | return(0L);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | // ***************************************************
|
---|
184 | // Create a memory presentation space that includes
|
---|
185 | // the memory device context obtained above.
|
---|
186 | // ***************************************************
|
---|
187 | ImageSize.cx = ulWidth;
|
---|
188 | ImageSize.cy = ulHeight;
|
---|
189 |
|
---|
190 | // ImageSize.cx = dwWidth;
|
---|
191 | // ImageSize.cy = dwHeight;
|
---|
192 |
|
---|
193 | hps = GpiCreatePS ( hab,
|
---|
194 | hdc,
|
---|
195 | &ImageSize,
|
---|
196 | PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
|
---|
197 | if ( !hps )
|
---|
198 | {
|
---|
199 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
200 | "No HPS...",
|
---|
201 | "Open Image File",
|
---|
202 | (HMODULE) NULL,
|
---|
203 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
204 | MB_ERROR );
|
---|
205 | DosFreeMem(pRowBuffer);
|
---|
206 | mmioClose (hmmio, 0L);
|
---|
207 | return(0L);
|
---|
208 | }
|
---|
209 |
|
---|
210 | // ***************************************************
|
---|
211 | // Create an uninitialized bitmap. This is where we
|
---|
212 | // will put all of the bits once we read them in.
|
---|
213 | // ***************************************************
|
---|
214 |
|
---|
215 | /*!!!!*/
|
---|
216 | // mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cxResolution=ulWidth;
|
---|
217 | // mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cyResolution=ulHeight;
|
---|
218 |
|
---|
219 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx=ulWidth;
|
---|
220 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy=ulHeight;
|
---|
221 |
|
---|
222 | /*!!!!*/
|
---|
223 | hbm = GpiCreateBitmap ( hps,
|
---|
224 | &mmImgHdr.mmXDIBHeader.BMPInfoHeader2,
|
---|
225 | 0L,
|
---|
226 | NULL,
|
---|
227 | NULL);
|
---|
228 |
|
---|
229 | if ( !hbm )
|
---|
230 | {
|
---|
231 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
232 | "No HBITMAP...",
|
---|
233 | "Open Image File",
|
---|
234 | (HMODULE) NULL,
|
---|
235 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
236 | MB_ERROR );
|
---|
237 |
|
---|
238 | DosFreeMem(pRowBuffer);
|
---|
239 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
240 | return(0L);
|
---|
241 | }
|
---|
242 |
|
---|
243 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx=dwWidth;
|
---|
244 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy=dwHeight;
|
---|
245 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cxResolution=ulWidth;
|
---|
246 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cyResolution=ulHeight;
|
---|
247 |
|
---|
248 | sprintf(text, "%d %d", mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx,
|
---|
249 | mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy
|
---|
250 | );
|
---|
251 | WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
|
---|
252 | text,
|
---|
253 | "Open Image File",
|
---|
254 | (HMODULE) NULL,
|
---|
255 | (ULONG) MB_OK | MB_MOVEABLE |
|
---|
256 | MB_ERROR );
|
---|
257 |
|
---|
258 | // ***************************************************
|
---|
259 | // Select the bitmap into the memory device context.
|
---|
260 | // ***************************************************
|
---|
261 | hbReturnCode = GpiSetBitmap ( hps,
|
---|
262 | hbm );
|
---|
263 |
|
---|
264 | //***************************************************************
|
---|
265 | // LOAD THE BITMAP DATA FROM THE FILE
|
---|
266 | // One line at a time, starting from the BOTTOM
|
---|
267 | //*************************************************************** */
|
---|
268 |
|
---|
269 | for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ )
|
---|
270 | {
|
---|
271 | ulBytesRead = (ULONG) mmioRead ( hmmio,
|
---|
272 | pRowBuffer,
|
---|
273 | dwNumRowBytes );
|
---|
274 | if ( !ulBytesRead )
|
---|
275 | {
|
---|
276 | break;
|
---|
277 | }
|
---|
278 | /*
|
---|
279 | * Allow context switching while previewing.. Couldn't get
|
---|
280 | * it to work. Perhaps will get to it when time is available...
|
---|
281 | */
|
---|
282 | lReturnCode = GpiSetBitmapBits ( hps,
|
---|
283 | (LONG) dwRowCount,
|
---|
284 | (LONG) 1,
|
---|
285 | (PBYTE) pRowBuffer,
|
---|
286 | (PBITMAPINFO2) &mmImgHdr.mmXDIBHeader.BMPInfoHeader2);
|
---|
287 | }
|
---|
288 |
|
---|
289 |
|
---|
290 | ulReturnCode = mmioClose (hmmio, 0L);
|
---|
291 | DosFreeMem(pRowBuffer);
|
---|
292 |
|
---|
293 | return(hbm);
|
---|
294 | }
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 | static MRESULT EXPENTRY transparencyExampleProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
299 | {
|
---|
300 | RECTL rcl;
|
---|
301 | HPS hps;
|
---|
302 | HBITMAP hbm, hbmOld;
|
---|
303 | BITMAPINFOHEADER2 *ptr;
|
---|
304 | RGB2* rgb2;
|
---|
305 | int a, r,g,b,r2,g2,b2;
|
---|
306 | char *pvImage;
|
---|
307 | POINTL ptl= {0};
|
---|
308 | switch(msg)
|
---|
309 | {
|
---|
310 | case WM_PAINT:
|
---|
311 | hps=WinBeginPaint(hwnd, NULLHANDLE, NULL);
|
---|
312 |
|
---|
313 | WinQueryWindowRect(hwnd, &rcl);
|
---|
314 | WinDrawBitmap(hps, hBitmap, NULL, (PPOINTL)&ptl, 0,0,DBM_NORMAL);
|
---|
315 | #if 0
|
---|
316 | if(pbmpInfo2 && pvImageData) {
|
---|
317 | hbm=GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)pbmpInfo2, 0, NULLHANDLE, pbmpInfo2);
|
---|
318 | hbmOld=GpiSetBitmap(hps,hbm);
|
---|
319 |
|
---|
320 | ptr=malloc(sizeof(BITMAPINFOHEADER2)+sizeof(RGB2)*256);
|
---|
321 | if(ptr) {
|
---|
322 | memcpy(ptr, pbmpInfo2, sizeof(BITMAPINFOHEADER2)+sizeof(RGB2)*256);
|
---|
323 |
|
---|
324 | GpiDrawBits(hps, pvImageData, (PBITMAPINFO2) ptr, 4L, ptl, ROP_SRCCOPY, BBO_IGNORE);
|
---|
325 | free(ptr);
|
---|
326 | }/* if(ptr) */
|
---|
327 | GpiSetBitmap(hps, hbmOld);
|
---|
328 | GpiDeleteBitmap(hbm);
|
---|
329 | }/* End of if(pbmpInfo2 && pvImageData) */
|
---|
330 | else
|
---|
331 | WinFillRect(hps, &rcl, CLR_WHITE);
|
---|
332 | #endif
|
---|
333 | // WinFillRect(hps, &rcl, CLR_WHITE);
|
---|
334 |
|
---|
335 | WinEndPaint(hps);
|
---|
336 | return (MRESULT)0;
|
---|
337 | default:
|
---|
338 | break;
|
---|
339 | }
|
---|
340 | return WinDefWindowProc(hwnd, msg, mp1, mp2);
|
---|
341 | }
|
---|
342 |
|
---|
343 | MRESULT EXPENTRY imageDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
344 | {
|
---|
345 | SHORT sLen, sPos;
|
---|
346 | MRESULT mr;
|
---|
347 | RECTL rcl;
|
---|
348 | HWND hwndPtr;
|
---|
349 | ULONG ulValue;
|
---|
350 |
|
---|
351 | switch (msg)
|
---|
352 | {
|
---|
353 | case WM_INITDLG:
|
---|
354 | {
|
---|
355 | WinSubclassWindow(WinWindowFromID(hwnd, IDST_IMAGERECT),transparencyExampleProc);
|
---|
356 | break;
|
---|
357 | }
|
---|
358 | case WM_DESTROY:
|
---|
359 | break;
|
---|
360 | case WM_COMMAND:
|
---|
361 | switch(SHORT1FROMMP(mp1))
|
---|
362 | {
|
---|
363 | case DID_CANCEL:
|
---|
364 | return (MRESULT)0;
|
---|
365 | default:
|
---|
366 | break;
|
---|
367 | }
|
---|
368 | break;
|
---|
369 | case WM_CONTROL:
|
---|
370 | {
|
---|
371 | break;
|
---|
372 | }
|
---|
373 | default:
|
---|
374 | break;
|
---|
375 | }
|
---|
376 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 | int main (int argc, char *argv[])
|
---|
381 | {
|
---|
382 | HMQ hmq;
|
---|
383 | QMSG qmsg;
|
---|
384 | char text[CCHMAXPATH];
|
---|
385 | char title[CCHMAXPATH];
|
---|
386 | short a;
|
---|
387 | HWND hwndClient;
|
---|
388 | ULONG result;
|
---|
389 | ULONG rc;
|
---|
390 | HINI hIni;
|
---|
391 | char *chrPtr;
|
---|
392 |
|
---|
393 | hab=WinInitialize(0);
|
---|
394 | if(hab) {
|
---|
395 | hmq=WinCreateMsgQueue(hab,0);
|
---|
396 | if(hmq) {
|
---|
397 |
|
---|
398 | if((hBitmap=loadBitmap("D:\\Arbeitsoberflaeche\\BIKES.nnn", 100, 100,NULL))!=NULLHANDLE) {
|
---|
399 | if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, imageDialogProc, NULLHANDLE, 100, 0) == DID_ERROR )
|
---|
400 | {
|
---|
401 | WinDestroyMsgQueue( hmq );
|
---|
402 | WinTerminate( hab );
|
---|
403 | DosBeep(100,600);
|
---|
404 | }
|
---|
405 | }
|
---|
406 | }
|
---|
407 | WinDestroyMsgQueue(hmq);
|
---|
408 | WinTerminate(hab);
|
---|
409 | }
|
---|
410 | return 0;
|
---|
411 | }
|
---|