source: branches/v2.9/classes/mm-progs/imageconverter/imgconv.c

Last change on this file was 12, checked in by dryeo, 5 years ago

Use the toolkit headers, simple way to get the fourcc

File size: 42.2 KB
Line 
1/*
2 * imgconv.c (C) Chris Wohlgemuth 2002-2003
3 *
4 * This helper converts image files. It is called by the image classes
5 * when the 'convert' menu is chosen.
6 */
7/*
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22/*
23 * If you need another license for your project/product (commercial,
24 * noncommercial, whatever) contact me at
25 *
26 * http://www.os2world.com/cdwriting
27 * http://www.geocities.com/SiliconValley/Sector/5785/
28 *
29 */
30#define INCL_DOS
31#define INCL_DOSFILEMGR
32#define INCL_DOSERRORS
33#define INCL_WIN
34#define INCL_OS2MM
35#define INCL_MMIOOS2
36#define INCL_GPI
37#define INCL_PM
38
39#define USE_OS2_TOOLKIT_HEADERS
40#include <os2.h>
41
42#include <sys\types.h>
43#include <sys\stat.h>
44#include <stdio.h>
45#include <stdlib.h>
46#include <string.h>
47#include "os2me.h"
48#include "mmioos2.h"
49#include <mmio.h>
50#include "common.h"
51#include "mmres.h"
52#include "mmprogs_defaults.h"
53
54#include "sys_funcs.h"
55
56#ifndef MMIOM_QUERYIMAGE
57 #define MMIOM_QUERYIMAGE MMIOM_START + 39
58 #define MMIOM_QUERYIMAGECOUNT MMIOM_START + 40
59 #define MMIOM_SETIMAGE MMIOM_START + 41
60#endif
61
62#define MSG_CONVERTDONE 1L
63#define MSG_CONVERTPERCENT 2L
64#define MSG_CONVERTERROR 3L
65
66#define ID_TIMER 1
67#define TIMER_DELAY 200
68
69#define CONVERTBUFFERSIZE 500000
70#define NUMPARAMS 3
71
72/* argv[0]: progname
73 * argv[1]: imgfile
74 * argv[2]: IO proc name
75 */
76
77//#define DEBUG
78
79void HlpSendCommandToObject(char* chrObject, char* command);
80BOOL percentRegisterBarClass(void);
81BOOL IniSaveWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd);
82BOOL IniRestoreWindowPos(char * iniFile, char* chrApp, char *chrKey, HWND hwnd);
83BOOL IniSaveWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd);
84BOOL IniRestoreWindowClrs(char * chrIniFile, char* chrApp , HWND hwnd);
85BOOL HlpBuildMMProgIniFileName(char* chrProgname, char * chrBuffer, ULONG ulBufferSize);
86HMODULE queryResModuleHandle(char *chrExePath);
87void freeResHandle();
88BOOL getMessage(char* text,ULONG ulID, LONG lSizeText, HMODULE hResource,HWND hwnd);
89ULONG messageBox( char* text, ULONG ulTextID , LONG lSizeText,
90 char* title, ULONG ulTitleID, LONG lSizeTitle,
91 HMODULE hResource, HWND hwnd, ULONG ulFlags);
92
93char logName[]="convert.log";
94
95extern SWP swpWindow;
96BOOL bHaveWindowPos=FALSE;
97
98char chrTargetName[CCHMAXPATH]={0};
99char chrSourceName[CCHMAXPATH]={0};
100char chrProcName[CCHMAXPATH]={0};
101char chrIniFile[CCHMAXPATH];
102
103int numArgs;
104char* params[NUMPARAMS];
105
106#define NUMIOPROCS 1000
107int iIoProc; /* Position of IO-Proc in global data area of MMOS2. 0 based */
108int iPrivIOProc[NUMIOPROCS]; /* Number of possible IO-Procs. I'm lazy here and use a static array.
109 If there ever will be more than 1000 procs there'll be a problem... */
110
111
112TID tidThread=0;
113BOOL bBreak=FALSE;
114PMMFORMATINFO pMemFormatInfo=NULLHANDLE;
115HMODULE RESSOURCEHANDLE=0;
116BOOL bNoProcGiven=FALSE;
117HAB globalHab;
118/* BMP info for preview */
119BITMAPINFOHEADER2 bmpInfoHeader2;
120HBITMAP hBitmap;
121
122void pmUsage();
123
124//#define DEBUG
125
126#ifdef DEBUG
127void HlpWriteToTrapLog(const char* chrFormat, ...);
128#endif
129
130/*
131 Load an image file using IO-Procs
132 */
133HBITMAP loadBitmap ( PSZ pszFileName, PBITMAPINFOHEADER2 pBMPInfoHeader2)
134{
135 HBITMAP hbm;
136 MMIOINFO mmioinfo;
137 MMFORMATINFO mmFormatInfo;
138 HMMIO hmmio;
139 ULONG ulImageHeaderLength;
140 MMIMAGEHEADER mmImgHdr;
141 ULONG ulBytesRead;
142 ULONG dwNumRowBytes;
143 PBYTE pRowBuffer;
144 ULONG dwRowCount;
145 SIZEL ImageSize;
146 ULONG dwHeight, dwWidth;
147 SHORT wBitCount;
148 FOURCC fccStorageSystem;
149 ULONG dwPadBytes;
150 ULONG dwRowBits;
151 ULONG ulReturnCode;
152 ULONG dwReturnCode;
153 HBITMAP hbReturnCode;
154 LONG lReturnCode;
155 FOURCC fccIOProc;
156 HDC hdc;
157 HPS hps;
158
159
160 ulReturnCode = mmioIdentifyFile ( pszFileName,
161 0L,
162 &mmFormatInfo,
163 &fccStorageSystem,
164 0L,
165 0L);
166 /*
167 * If this file was NOT identified, then this function won't
168 * work, so return an error by indicating an empty bitmap.
169 */
170 if ( ulReturnCode == MMIO_ERROR )
171 {
172 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
173 return (0L);
174 }
175
176 /*
177 * If mmioIdentifyFile did not find a custom-written IO proc which
178 * can understand the image file, then it will return the DOS IO Proc
179 * info because the image file IS a DOS file.
180 */
181 if( mmFormatInfo.fccIOProc == FOURCC_DOS )
182 {
183 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
184 return ( 0L );
185 }
186 /*
187 * Ensure this is an IMAGE IOproc, and that it can read
188 * translated data
189 */
190 if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
191 ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
192 {
193 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR, queryModuleHandle());
194 return (0L);
195 }
196 else
197 {
198 fccIOProc = mmFormatInfo.fccIOProc;
199 }
200
201 /* Clear out and initialize mminfo structure */
202 memset ( &mmioinfo, 0L, sizeof ( MMIOINFO ) );
203 mmioinfo.fccIOProc = fccIOProc;
204 mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
205 hmmio = mmioOpen ( (PSZ) pszFileName,
206 &mmioinfo,
207 MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
208 if ( ! hmmio )
209 {
210 // If file could not be opened, return with error
211 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_OPENFILEERROR, queryModuleHandle());
212 return (0L);
213 }
214
215
216 dwReturnCode = mmioQueryHeaderLength ( hmmio,
217 (PLONG)&ulImageHeaderLength,
218 0L,
219 0L);
220 if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
221 {
222 /* We have a problem.....possibly incompatible versions */
223 ulReturnCode = mmioClose (hmmio, 0L);
224 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOIMGIOPROCERROR);
225 return (0L);
226 }
227
228 ulReturnCode = mmioGetHeader ( hmmio,
229 &mmImgHdr,
230 (LONG) sizeof ( MMIMAGEHEADER ),
231 (PLONG)&ulBytesRead,
232 0L,
233 0L);
234
235 if ( ulReturnCode != MMIO_SUCCESS )
236 {
237 /* Header unavailable */
238 ulReturnCode = mmioClose (hmmio, 0L);
239 return (0L);
240 }
241
242 /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
243 *pBMPInfoHeader2=mmImgHdr.mmXDIBHeader.BMPInfoHeader2;
244
245 /*
246 * Determine the number of bytes required, per row.
247 * PLANES MUST ALWAYS BE = 1
248 */
249 dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
250 dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
251 wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
252 dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
253 dwNumRowBytes = dwRowBits >> 3;
254
255 /*
256 * Account for odd bits used in 1bpp or 4bpp images that are
257 * NOT on byte boundaries.
258 */
259 if ( dwRowBits % 8 )
260 {
261 dwNumRowBytes++;
262 }
263 /*
264 * Ensure the row length in bytes accounts for byte padding.
265 * All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
266 * The data FROM an IOProc should always appear in this form.
267 */
268 dwPadBytes = ( dwNumRowBytes % 4 );
269 if ( dwPadBytes )
270 {
271 dwNumRowBytes += 4 - dwPadBytes;
272 }
273
274 /* Allocate space for ONE row of pels */
275 if ( DosAllocMem( (PPVOID)&pRowBuffer,
276 (ULONG)dwNumRowBytes,
277 fALLOC))
278 {
279 ulReturnCode = mmioClose (hmmio, 0L);
280 // showMsgBox(IDSTR_CWIMAGETITLE, IDSTR_NOMEMERROR, queryModuleHandle());
281 return(0L);
282 }
283
284 /* Create a device context */
285 hdc=DevOpenDC(globalHab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
286 if(hdc==NULLHANDLE)
287 {
288 DosFreeMem(pRowBuffer);
289 mmioClose (hmmio, 0L);
290 return(0L);
291 }
292
293
294 // ***************************************************
295 // Create a memory presentation space that includes
296 // the memory device context obtained above.
297 // ***************************************************
298
299 ImageSize.cx = dwWidth;
300 ImageSize.cy = dwHeight;
301
302 hps = GpiCreatePS ( globalHab,
303 hdc,
304 &ImageSize,
305 PU_PELS | GPIT_NORMAL | GPIA_ASSOC );
306 // PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
307 if ( !hps )
308 {
309#ifdef DEBUG
310 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
311 "No HPS...",
312 "Open Image File",
313 (HMODULE) NULL,
314 (ULONG) MB_OK | MB_MOVEABLE |
315 MB_ERROR );
316#endif
317 DevCloseDC(hdc);
318 DosFreeMem(pRowBuffer);
319 mmioClose (hmmio, 0L);
320 return(0L);
321 }
322
323 // GpiSelectPalette(hps, NULLHANDLE);
324 // ***************************************************
325 // Create an uninitialized bitmap. This is where we
326 // will put all of the bits once we read them in.
327 // ***************************************************
328 hbm = GpiCreateBitmap ( hps,
329 pBMPInfoHeader2,
330 0L,
331 NULL,
332 NULL);
333
334 if ( !hbm )
335 {
336#ifdef DEBUG
337 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
338 "No HBITMAP...",
339 "Open Image File",
340 (HMODULE) NULL,
341 (ULONG) MB_OK | MB_MOVEABLE |
342 MB_ERROR );
343#endif
344 GpiDestroyPS(hps);
345 DevCloseDC(hdc);
346 DosFreeMem(pRowBuffer);
347 ulReturnCode = mmioClose (hmmio, 0L);
348 return(0L);
349 }
350
351 // ***************************************************
352 // Select the bitmap into the memory device context.
353 // ***************************************************
354 hbReturnCode = GpiSetBitmap ( hps,
355 hbm );
356
357 //***************************************************************
358 // LOAD THE BITMAP DATA FROM THE FILE
359 // One line at a time, starting from the BOTTOM
360 //*************************************************************** */
361
362 for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ )
363 {
364 ulBytesRead = (ULONG) mmioRead ( hmmio,
365 pRowBuffer,
366 dwNumRowBytes );
367 if ( !ulBytesRead )
368 {
369 break;
370 }
371 /*
372 * Allow context switching while previewing.. Couldn't get
373 * it to work. Perhaps will get to it when time is available...
374 */
375 lReturnCode = GpiSetBitmapBits ( hps,
376 (LONG) dwRowCount,
377 (LONG) 1,
378 (PBYTE) pRowBuffer,
379 (PBITMAPINFO2) pBMPInfoHeader2);
380 }
381
382 /* Clean up */
383 hbReturnCode = GpiSetBitmap ( hps,
384 NULLHANDLE );
385 ulReturnCode = mmioClose (hmmio, 0L);
386 DosFreeMem(pRowBuffer);
387 GpiDestroyPS(hps);
388 DevCloseDC(hdc);
389
390 return(hbm);
391}
392
393
394/*
395 Create a BMP of another size from an already loaded BMP.
396*/
397HBITMAP createNewBitmap ( HBITMAP hbm,
398 PBITMAPINFOHEADER2 pBmpInfoHeader2,
399 HWND hwnd)
400 // ULONG ulWidth,
401 // ULONG ulHeight)
402{
403 HBITMAP hbmTarget;
404 SIZEL ImageSize;
405 HBITMAP hbReturnCode;
406 HDC hdc;
407 HPS hps;
408 BITMAPINFOHEADER2 bmpih2;
409 POINTL aptl[4];
410 ULONG ulWidth, ulHeight;
411 SWP swp;
412
413 /*
414 * Get position of image frame
415 */
416 WinQueryWindowPos ( hwnd, &swp);
417
418 /* Image size */
419
420 ulHeight = bmpInfoHeader2.cy;
421 ulWidth = bmpInfoHeader2.cx;
422
423 if(ulWidth <=swp.cx && ulHeight <= swp.cy)
424 {
425 aptl[0].x=0;
426 aptl[1].x=aptl[0].x+ulWidth;
427
428 aptl[0].y=0;
429 aptl[1].y=aptl[0].y+ulHeight;
430 }
431 else {
432 float fWidth, fHeight, fRes;
433
434 fWidth=(float)swp.cx/(float)ulWidth;
435 fHeight=(float)swp.cy/(float)ulHeight;
436 fRes=( fWidth>fHeight ? fHeight : fWidth);
437
438
439 aptl[0].x=0;
440 aptl[1].x=aptl[0].x+ulWidth*fRes;
441
442 aptl[0].y=0;
443 aptl[1].y=aptl[0].y+ulHeight*fRes;
444 }
445
446 aptl[2].x = 0; // source lower left
447 aptl[2].y = 0;
448
449 aptl[3].x = ulWidth; // source upper right
450 aptl[3].y = ulHeight;
451
452#if 0
453 sprintf(text, "BMP: %d %d, Window: %d %d , new: %d %d", ulWidth, ulHeight, swp.cx, swp.cy,
454 aptl[1].x-aptl[0].x, aptl[1].y-aptl[0].y);
455 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
456 text,
457 "Create new bitmap",
458 (HMODULE) NULL,
459 (ULONG) MB_OK | MB_MOVEABLE |
460 MB_ERROR );
461#endif
462
463 if(!ulWidth || !ulHeight)
464 return 0L;
465
466 /* Create a device context */
467 hdc=DevOpenDC(globalHab, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
468 if(hdc==NULLHANDLE)
469 {
470 return(0L);
471 }
472
473 // ***************************************************
474 // Create a memory presentation space that includes
475 // the memory device context obtained above.
476 // ***************************************************
477 ImageSize.cx = ulWidth;
478 ImageSize.cy = ulHeight;
479 hps = GpiCreatePS ( globalHab,
480 hdc,
481 &ImageSize,
482 PU_PELS | GPIT_NORMAL | GPIA_ASSOC );
483 if ( !hps )
484 {
485 DevCloseDC(hdc);
486 return(0L);
487 }
488
489 /* Now scale the bitmap */
490 memcpy(&bmpih2, pBmpInfoHeader2, sizeof(BITMAPINFOHEADER2));
491
492 bmpih2.cx=aptl[1].x-aptl[0].x;
493 bmpih2.cy=aptl[1].y-aptl[0].y;
494
495 bmpih2.cbImage=(((ulWidth*(1<<bmpih2.cPlanes)*(1<<bmpih2.cBitCount))+31) /32)*ulHeight;
496 // ***************************************************
497 // Create an uninitialized bitmap. This is where we
498 // ***************************************************
499
500 hbmTarget = GpiCreateBitmap ( hps,
501 &bmpih2,
502 0L,
503 NULL,
504 NULL);
505 if ( !hbmTarget )
506 {
507 GpiDestroyPS(hps);
508 DevCloseDC(hdc);
509 return(0L);
510 }
511
512 /* Blit it */
513 hbReturnCode = GpiSetBitmap ( hps, hbmTarget );
514
515 GpiWCBitBlt(hps, hbm,4L, aptl, ROP_SRCCOPY, BBO_IGNORE);
516
517 hbReturnCode = GpiSetBitmap( hps, NULLHANDLE );
518 GpiDestroyPS(hps);
519 DevCloseDC(hdc);
520 pBmpInfoHeader2->cbFix=sizeof(BITMAPINFOHEADER2);
521 GpiQueryBitmapInfoHeader(hbmTarget, pBmpInfoHeader2);
522
523#if 0
524 sprintf(text, "BMP: %d %d, Window: %d %d , new: %d %d", ulWidth, ulHeight, swp.cx, swp.cy,
525 pBmpInfoHeader2->cx, pBmpInfoHeader2->cy);
526 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
527 text,
528 "Create new bitmap",
529 (HMODULE) NULL,
530 (ULONG) MB_OK | MB_MOVEABLE |
531 MB_ERROR );
532#endif
533 return(hbmTarget);
534}
535
536
537
538BOOL createTargetName(char *sourceName, char *chrExt)
539{
540 char *textPtr;
541
542 strcpy(chrTargetName, sourceName);
543 if((textPtr=strrchr(chrTargetName, '.'))!=NULLHANDLE)
544 *textPtr=0;
545 else
546 textPtr=chrTargetName;
547 strcat(textPtr,".");
548 strcat(textPtr, chrExt);
549
550 return TRUE;
551}
552
553
554BOOL insertIOProcItems( HWND hwndDrop )
555{
556 // CHAR szBuffer[ sizeof( FOURCC ) + CCHMAXPATH + 4 ];
557 MMFORMATINFO mmFormatInfo;
558 PMMFORMATINFO pmmFormatInfoArray;
559 ULONG ulReturnCode;
560 LONG lFormatsRead;
561 LONG index;
562 LONG lBytesRead;
563 LONG lNumIOProcs;
564 int sIdx;
565 memset( &mmFormatInfo,
566 '\0',
567 sizeof(MMFORMATINFO) );
568
569 mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
570 mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;
571 ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
572 &lNumIOProcs,
573 0,
574 0 );
575
576 if( ulReturnCode != MMIO_SUCCESS )
577 {
578 /*
579 * Error - mmioQueryFormatCount failed.
580 */
581 return FALSE;
582 }
583
584 /*
585 * Allocate enough memory for n number of FormatInfo blocks
586 */
587 pmmFormatInfoArray = (PMMFORMATINFO) malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
588 pMemFormatInfo=pmmFormatInfoArray;
589 if( pmmFormatInfoArray == NULL )
590 {
591 /*
592 * Could not allocate enough memory for mmFormatInfo array.
593 */
594 return FALSE;
595 }
596
597 /*
598 * call mmioGetFormats to get info on the formats supported.
599 */
600 ulReturnCode = mmioGetFormats( &mmFormatInfo,
601 lNumIOProcs,
602 pmmFormatInfoArray,
603 &lFormatsRead,
604 0,
605 0 );
606 if( ulReturnCode != MMIO_SUCCESS )
607 {
608 /*
609 * mmioGetFormats failed.
610 */
611 free(pmmFormatInfoArray);
612 return FALSE;
613 }
614
615 if( lFormatsRead != lNumIOProcs )
616 {
617 /*
618 * Error in MMIO - number of formats read in by
619 * mmioGetFormats is not equal to number of formats
620 * found by mmioQueryFormatCount.
621 */
622 free(pmmFormatInfoArray);
623 return FALSE;
624 }
625
626
627 for ( index = 0, sIdx=0; index <lNumIOProcs; index++ )
628 {
629 char szName[CCHMAXPATH];
630
631 mmioGetFormatName(pmmFormatInfoArray, szName, &lBytesRead, 0L, 0L);
632 /* Insert NULL string terminator */
633 *( szName + lBytesRead ) = (CHAR)NULL;
634
635
636 /* Compressed TIF is not supported because the Warp 4 IO-Procs are
637 broken. */
638 if(pmmFormatInfoArray->fccIOProc!=mmioStringToFOURCC("TFMC",MMIO_TOUPPER) &&
639 pmmFormatInfoArray->fccIOProc!=mmioStringToFOURCC("TFIC",MMIO_TOUPPER) &&
640 (pmmFormatInfoArray->ulFlags & MMIO_CANWRITETRANSLATED))
641 {
642 /* Insert into list box */
643 WinSendMsg(hwndDrop, LM_INSERTITEM,(MPARAM)LIT_END,
644 (MPARAM)szName);
645
646#ifdef DEBUG
647 HlpWriteToTrapLog("------ %d private idx: %d, IO-Proc: %s %s\n", index, sIdx,
648 pmmFormatInfoArray->szDefaultFormatExt,
649 szName);
650#endif
651
652 iPrivIOProc[sIdx]=index;
653
654 /* Set text field */
655 if(bNoProcGiven) {
656 WinSetWindowText(hwndDrop, szName);
657 createTargetName(chrSourceName, pmmFormatInfoArray->szDefaultFormatExt);
658 iIoProc=iPrivIOProc[sIdx];
659 bNoProcGiven=FALSE;
660 }
661 else {
662 if(!stricmp(szName, chrProcName)) {
663 WinSetWindowText(hwndDrop, szName);
664 /* Create target name */
665 createTargetName(chrSourceName, pmmFormatInfoArray->szDefaultFormatExt);
666 iIoProc=iPrivIOProc[sIdx];
667 }
668 }
669 sIdx++;
670 }
671 /*
672 * advance to next entry in mmFormatInfo array
673 */
674 pmmFormatInfoArray++;
675 }
676 return TRUE;
677}
678
679BOOL DoConvert(HWND hwnd,
680 PSZ pszSource, // Source file name
681 PSZ pszTarget,
682 FOURCC fccTargetIOProc) //
683{
684 MMIOINFO mmioinfoSource;
685 MMIOINFO mmioinfoTarget;
686 HMMIO hmmioSource;
687 HMMIO hmmioTarget;
688 ULONG ulImageHeaderLength;
689 MMIMAGEHEADER mmImgHdr;
690 ULONG ulBytesRead;
691 ULONG dwNumRowBytes;
692 PBYTE pRowBuffer;
693 ULONG dwRowCount;
694 ULONG dwWidth;
695 ULONG dwHeight;
696 ULONG dwPadBytes;
697 ULONG dwRowBits;
698 LONG rc;
699 LONG rcSrcQueryCount = 0;
700 LONG rcTrgQueryCount = 0;
701 LONG rcTrgSetImage = 0;
702 ULONG iIndex, iCount, iCount2;
703
704 MMFORMATINFO mmFormatInfo;
705 FOURCC fccSourceIOProc;
706 FOURCC fccStorageSystem;
707
708 rc = mmioIdentifyFile ( pszSource,
709 0L,
710 &mmFormatInfo,
711 &fccStorageSystem,
712 0L,
713 0L);
714
715 /*
716 * If this file was NOT identified, then this function won't
717 * work, so return an error by indicating an empty bitmap.
718 */
719
720 if ( rc == MMIO_ERROR )
721 {
722 return (0L);
723 }
724 fccSourceIOProc=mmFormatInfo.fccIOProc;
725
726 /*******************************/
727 /* Set up/open the SOURCE file */
728 /*******************************/
729 memset (&mmioinfoSource, 0L, sizeof (MMIOINFO));
730 mmioinfoSource.fccIOProc = fccSourceIOProc;
731 mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
732
733 hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource,
734 MMIO_READ | MMIO_DENYWRITE
735 | MMIO_NOIDENTIFY);
736
737 if (!hmmioSource)
738 return (FALSE);
739
740 /*******************************/
741 /* Set up/open the TARGET file */
742 /*******************************/
743
744 memset (&mmioinfoTarget, 0L, sizeof (MMIOINFO));
745 mmioinfoTarget.fccIOProc = fccTargetIOProc;
746 mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
747
748 hmmioTarget = mmioOpen ((PSZ)pszTarget,
749 &mmioinfoTarget,
750 MMIO_CREATE | MMIO_WRITE |
751 MMIO_DENYWRITE | MMIO_NOIDENTIFY);
752
753 if (!hmmioTarget)
754 {
755 mmioClose (hmmioSource, 0L);
756 return (FALSE);
757 }
758
759#ifdef DEBUG
760 HlpWriteToTrapLog("Target opened.\n");
761#endif
762
763 // find out if source has multiple image support
764 rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0);
765 if (rcSrcQueryCount) iCount = 1;
766
767 // find out if the target has multiple image support
768 rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0);
769
770 for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */
771
772 if (!rcSrcQueryCount && !rcTrgQueryCount) { /* if Both support images */
773
774 /* Determine if the target can write arrays, and if not */
775 /* then write the the default image from the source */
776
777 if (rcTrgSetImage && iIndex > 0) break; /* Target Can't Write array */
778
779 /* Now, determine if the target can write arrays */
780 rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
781
782 if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
783
784 } else if (!rcSrcQueryCount) { /* Source does but target doesn't */
785 /* Use the default image from source to copy to target */
786 /* so do set the index of the first, let it default */
787 /* get the base photo cd image (2 of 5) */
788 if (iIndex > 0) break;
789 } else if (!rcTrgQueryCount) { /* Target does but source doesn't */
790 /* Use the only image to do a default write to target */
791 } else {
792 /* neither do: just write one image from here to there */
793 }
794
795 /****************************/
796 /* Obtain the SOURCE HEADER */
797 /****************************/
798 mmioQueryHeaderLength (hmmioSource, (PLONG)&ulImageHeaderLength, 0L, 0L);
799 if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
800 /* We have a problem.....possibly incompatible versions */
801 {
802 mmioClose (hmmioSource, 0L);
803 mmioClose (hmmioTarget, 0L);
804 return (FALSE);
805 }
806
807 rc = (LONG)mmioGetHeader (hmmioSource, &mmImgHdr,
808 (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
809 0L, 0L);
810
811 if (rc != MMIO_SUCCESS)
812 /* Header unavailable */
813 {
814 mmioClose (hmmioSource, 0L);
815 mmioClose (hmmioTarget, 0L);
816 return (FALSE);
817 }
818
819
820 /*************************/
821 /* Set the TARGET HEADER */
822 /*************************/
823 mmioQueryHeaderLength (hmmioTarget, (PLONG)&ulImageHeaderLength, 0L, 0L);
824 if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
825 {
826 /* We have a problem.....possibly incompatible versions */
827 mmioClose (hmmioSource, 0L);
828 mmioClose (hmmioTarget, 0L);
829 return (FALSE);
830 }
831
832
833 /* Use the SAME data as came from the SOURCE FILE. It must be
834 compatible with the OS/2 bitmaps, etc. */
835 rc = (LONG)mmioSetHeader (hmmioTarget, &mmImgHdr,
836 (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
837 0L, 0L);
838
839 if (rc != MMIO_SUCCESS)
840 /* Header unavailable */
841 {
842 mmioClose (hmmioSource, 0L);
843 mmioClose (hmmioTarget, 0L);
844 return (FALSE);
845 }
846
847#ifdef DEBUG
848 HlpWriteToTrapLog("Target header set.\n");
849#endif
850
851 /* Determine the number of bytes required, per row */
852 /* PLANES MUST ALWAYS BE = 1 */
853 dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
854 dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
855 dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
856 dwNumRowBytes = dwRowBits >> 3;
857
858 /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */
859 if (dwRowBits % 8)
860 dwNumRowBytes++;
861
862 /* Ensure the row length in bytes accounts for byte padding. All bitmap data rows
863 must are aligned on LONG/4-BYTE boundaries. The data FROM an IOProc
864 should always appear in this form. */
865 dwPadBytes = (dwNumRowBytes % 4);
866 if (dwPadBytes)
867 dwNumRowBytes += 4 - dwPadBytes;
868
869 /* Allocate space for one row */
870 if (DosAllocMem((PVOID)&pRowBuffer, (ULONG)dwNumRowBytes, fALLOC))
871 {
872 mmioClose (hmmioSource, 0L);
873 mmioClose (hmmioTarget, 0L);
874 return(FALSE);
875 }
876
877 for (dwRowCount = 0;
878 dwRowCount < dwHeight;
879 dwRowCount++)
880 {
881 ulBytesRead = (ULONG)mmioRead (hmmioSource, pRowBuffer, dwNumRowBytes);
882
883 if (ulBytesRead) {
884 LONG lWritten;
885 lWritten=mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
886#ifdef DEBUG
887 HlpWriteToTrapLog("ulBytesRead: %d, lWritten: %d.\n", ulBytesRead, lWritten);
888#endif
889
890 }
891 else
892 break;
893
894 if(dwHeight)
895 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(dwRowCount*100/dwHeight));
896 }
897 }
898 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(100));
899 mmioClose (hmmioTarget, 0L);
900 mmioClose (hmmioSource, 0L);
901 DosFreeMem(pRowBuffer);
902
903 return(TRUE);
904}
905
906void _Optlink convertThreadFunc (void *arg)
907{
908 HAB hab;
909 HMQ hmq;
910 HWND hwnd=(HWND)arg;
911
912 hab=WinInitialize(0);
913 if(hab) {
914 hmq=WinCreateMsgQueue(hab,0);
915 if(hmq) {
916
917 DoConvert(hwnd,
918 chrSourceName,
919 chrTargetName, pMemFormatInfo[iIoProc].fccIOProc);
920
921
922
923 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTDONE), 0);
924 DosSleep(1000);
925 WinDestroyMsgQueue(hmq);
926 }
927 WinTerminate(hab);
928 }
929 tidThread=0;
930 bBreak=FALSE;
931}
932
933/* Start the convert thread. hwnd is the HWND of our main dialog */
934void convertImageFile(HWND hwnd)
935{
936 tidThread=_beginthread(convertThreadFunc,NULL, 65535*32, (void*)hwnd); //Fehlerbehandlung fehlt
937 if(tidThread==-1) {
938 DosBeep(100, 500);
939 tidThread=0;
940 }
941}
942
943VOID DrawBitmap ( HWND hwnd )
944{
945 SWP swp;
946 POINTL aptl[4];
947 HPS hps;
948 BOOL bReturnCode;
949 ULONG ulHeight;
950 ULONG ulWidth;
951
952 hps = WinBeginPaint ( hwnd,
953 0,
954 NULL);
955 /*
956 * Get position of image frame
957 */
958 bReturnCode = WinQueryWindowPos ( hwnd, &swp);
959
960 /* Center image */
961 ulHeight = bmpInfoHeader2.cy;
962 ulWidth = bmpInfoHeader2.cx;
963 if(ulWidth <=swp.cx && ulHeight <= swp.cy)
964 {
965 aptl[0].x=(swp.cx-ulWidth)/2;
966 aptl[1].x=aptl[0].x+ulWidth;
967
968 aptl[0].y=(swp.cy-ulHeight)/2;
969 aptl[1].y=aptl[0].y+ulHeight;
970 }
971 else {
972 float fWidth, fHeight, fRes;
973
974 fWidth=(float)swp.cx/(float)ulWidth;
975 fHeight=(float)swp.cy/(float)ulHeight;
976 fRes=( fWidth>fHeight ? fHeight : fWidth);
977
978
979 aptl[0].x=(swp.cx-ulWidth*fRes)/2;
980 aptl[1].x=aptl[0].x+ulWidth*fRes;
981
982 aptl[0].y=(swp.cy-ulHeight*fRes)/2;
983 aptl[1].y=aptl[0].y+ulHeight*fRes;
984 }
985
986 aptl[2].x = 0; // source lower left
987 aptl[2].y = 0;
988
989 aptl[3].x = ulWidth; // source upper right
990 aptl[3].y = ulHeight;
991
992 /*
993 * Call GpiBitBlt and supply 4 aptl structures. This tells
994 * it to stretch or compress the bitmap depending on what is
995 * in the aptl structures. See above lines for their current
996 * settings.
997 */
998
999 WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL|DBM_STRETCH);
1000
1001#if 0
1002 aptl[0].x=0;
1003 aptl[0].y=0;
1004 //aptl[1].x=100;
1005 //aptl[1].y=100;
1006 // WinDrawBitmap(hps, hBitmap, NULLHANDLE, (PPOINTL)aptl, 0, 0, DBM_NORMAL/*|DBM_STRETCH*/);
1007#endif
1008 bReturnCode = WinEndPaint (hps);
1009}
1010
1011MRESULT EXPENTRY bmpPreviewProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1012{
1013
1014 switch (msg)
1015 {
1016 case WM_PAINT:
1017 {
1018 if (!WinIsWindowVisible(hwnd))
1019 {
1020 return((MRESULT)NULL);
1021 }
1022 DrawBitmap(hwnd);
1023 return MRTRUE;
1024 }
1025 default:
1026 break;
1027 }
1028 return WinDefWindowProc( hwnd, msg, mp1, mp2);
1029}
1030/* This Proc handles the on-the-fly data CD writing */
1031MRESULT EXPENTRY decodeStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1032{
1033 char text[CCHMAXPATH*4 +10];
1034 // char title[CCHMAXPATH*4];
1035 SWCNTRL swctl;
1036 PID pid;
1037 int iPercent;
1038
1039 switch (msg)
1040 {
1041 case WM_INITDLG:
1042#if 0
1043 sprintf(text,"1: %s, 2: %s, 3: %s 4: %s 5: %s 6: %s",params[1],params[2],params[3],
1044 params[4], params[4],params[4]);
1045 WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
1046 params[4],
1047 0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
1048#endif
1049
1050 WinSendMsg(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
1051
1052 /* Filename */
1053 WinSetWindowText(WinWindowFromID(hwnd,IDST_IMGCONVERTNAME), chrSourceName);
1054
1055 /* Set dialog font to WarpSans for Warp 4 and above */
1056 if(SysQueryOSRelease()>=40) {
1057 WinSetPresParam(hwnd,
1058 PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
1059 DEFAULT_DIALOG_FONT );
1060 }
1061
1062 /* Subclass preview area */
1063 WinSubclassWindow(WinWindowFromID(hwnd, IDSR_BMP), bmpPreviewProc);
1064
1065 /* Create a small BMP */
1066 if(hBitmap) {
1067 HBITMAP hBitmapTemp;
1068
1069 hBitmapTemp=createNewBitmap ( hBitmap, &bmpInfoHeader2, WinWindowFromID(hwnd, IDSR_BMP));
1070 GpiDeleteBitmap(hBitmap);
1071 hBitmap=hBitmapTemp;
1072 }
1073
1074 /* Set percent bars to 0. */
1075 WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS),"0#0%");
1076 WinSendMsg(WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), EM_SETTEXTLIMIT,
1077 MPFROMSHORT((SHORT)CCHMAXPATH),0);
1078 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
1079
1080 insertIOProcItems( WinWindowFromID(hwnd, IDDD_IMGIOPROC) );
1081
1082 WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );
1083
1084 IniRestoreWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
1085 IniRestoreWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
1086
1087 /* Add switch entry */
1088 memset(&swctl,0,sizeof(swctl));
1089 WinQueryWindowProcess(hwnd,&pid,NULL);
1090 swctl.hwnd=hwnd;
1091 swctl.uchVisibility=SWL_VISIBLE;
1092 swctl.idProcess=pid;
1093 swctl.bProgType=PROG_DEFAULT;
1094 swctl.fbJump=SWL_JUMPABLE;
1095 WinAddSwitchEntry(&swctl);
1096
1097 WinSetFocus(HWND_DESKTOP, hwnd);
1098
1099 return (MRESULT) TRUE;
1100 /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */
1101 case WM_APPTERMINATENOTIFY:
1102 switch(LONGFROMMP(mp1))
1103 {
1104 case MSG_CONVERTERROR:
1105 case MSG_CONVERTDONE:
1106 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), TRUE);
1107 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
1108 break;
1109 case MSG_CONVERTPERCENT:
1110 iPercent=LONGFROMMP(mp2);
1111 if(iPercent>100)
1112 iPercent=100;
1113 if(iPercent<0)
1114 iPercent=0;
1115
1116 /* Update track percent bar value. The helper prog sends us the actual decoded %. */
1117 sprintf(text,"%d#%d%%", iPercent, iPercent);
1118 WinSetWindowText(WinWindowFromID(hwnd,IDBAR_IMGCONVERTPROGRESS), text);
1119 break;
1120 default:
1121 break;
1122 }
1123 return FALSE;
1124 case WM_CLOSE:
1125 if(tidThread) {
1126 bBreak=TRUE;
1127 if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
1128 {
1129 /* Save window position */
1130 IniSaveWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
1131 IniSaveWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
1132 WinDismissDlg(hwnd,0);
1133 }
1134 else
1135 return FALSE;
1136 }
1137 /* Save window position */
1138 IniSaveWindowPos(chrIniFile, INI_IMGCONV_APP, INI_WINDOWPOS_KEY, hwnd);
1139 IniSaveWindowClrs(chrIniFile, INI_IMGCONV_APP , hwnd);
1140 WinDismissDlg(hwnd,0);
1141 return FALSE;
1142 case WM_CONTROL:
1143 if(SHORT1FROMMP(mp1)==IDDD_IMGIOPROC)
1144 {
1145 if(SHORT2FROMMP(mp1)==EN_CHANGE) {
1146 SHORT sIdx;
1147
1148 sIdx=SHORT1FROMMR(WinSendMsg(HWNDFROMMP(mp2),LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST),0));
1149
1150 iIoProc=iPrivIOProc[sIdx];
1151
1152 createTargetName(chrSourceName, pMemFormatInfo[iIoProc].szDefaultFormatExt);
1153 WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), chrTargetName );
1154 }
1155 }
1156 break;
1157 case WM_TIMER:
1158 if(SHORT1FROMMP(mp1)==ID_TIMER)
1159 {
1160 if(!tidThread) {
1161 /* Convert thread ended. Quit. */
1162 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER);
1163 WinPostMsg(hwnd, WM_CLOSE, 0, 0);
1164 }
1165 return MRFALSE;
1166 }
1167 break;
1168 case WM_COMMAND:
1169 switch(SHORT1FROMMP(mp1))
1170 {
1171 case IDPB_IMGCONVERTBROWSE:
1172 {
1173 char chrTitle[200];
1174 FILEDLG fd = { 0 };
1175 /* User pressed the browse button */
1176 fd.cbSize = sizeof( fd );
1177 /* It's an centered 'Open'-dialog */
1178 fd.fl = FDS_OPEN_DIALOG|FDS_CENTER;
1179 /* Title: "Search CDRecord/2" */
1180 // getMessage(text,IDSTR_FDLGSEARCHCDR2TITLE,sizeof(text), hSettingsResource,hwnd);
1181 /* Set the title of the file dialog */
1182 fd.pszTitle = chrTitle;
1183 if(!getMessage(chrTitle, IDSTR_IMAGEBROWSETITLE, sizeof(chrTitle), RESSOURCEHANDLE, hwnd))
1184 fd.pszTitle = "Image name";
1185 /* Only show * files */
1186 //sprintf(fd.szFullFile,"%s","*");
1187 strcpy(fd.szFullFile, chrTargetName);
1188 if( WinFileDlg( HWND_DESKTOP, hwnd, &fd ) == NULLHANDLE )
1189 {
1190 /* WinFileDlg failed */
1191 break;
1192 }
1193 if( fd.lReturn == DID_OK )
1194 {
1195 WinSetWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME), fd.szFullFile );
1196 }
1197 break;
1198 }
1199 case IDPB_IMGCONVERTCLOSE:
1200 bBreak=TRUE;
1201 if(!WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, TIMER_DELAY))
1202 WinPostMsg(hwnd, WM_CLOSE, 0, 0);/* Timer error so do a hard quit */
1203 break;
1204 case IDPB_IMGCONVERTABORT:
1205 bBreak=TRUE;
1206 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), FALSE);
1207 break;
1208 case IDPB_IMGCONVERTOK:
1209 {
1210 // FSALLOCATE fsAlloc;
1211 // long long lFreeSpace;
1212 // ULONG ulDiskNum;
1213 // char cLetter;
1214
1215 /* Get target name */
1216 WinQueryWindowText( WinWindowFromID(hwnd,IDEF_IMGCONVERTTARGETNAME),
1217 sizeof(chrTargetName), chrTargetName );
1218#if 0
1219 /* Check if diskspace is sufficient */
1220 cLetter=tolower(chrTargetName[0]);
1221 ulDiskNum=cLetter-'a'+1;
1222 if(DosQueryFSInfo(ulDiskNum, FSIL_ALLOC,&fsAlloc,sizeof(fsAlloc)))
1223 lFreeSpace=0;
1224 else
1225 lFreeSpace=fsAlloc.cUnitAvail*fsAlloc.cbSector*fsAlloc.cSectorUnit;
1226
1227 if(lFreeSpace<lAudioSize) {
1228 /*
1229 Text:
1230 Title:
1231 */
1232 getMessage(title, IDSTR_CONVERTNOSPACETEXT,sizeof(title), RESSOURCEHANDLE, hwnd);
1233 sprintf(text,title,lAudioSize/1000000 );
1234 getMessage(title, IDSTR_CONVERTNOSPACETITLE,sizeof(title), RESSOURCEHANDLE, hwnd);
1235 WinMessageBox( HWND_DESKTOP, hwnd, text,
1236 title,
1237 1234UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
1238 }
1239 else {
1240 /* Start decoding an audio file */
1241 WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTOK), FALSE);
1242 WinEnableWindow( WinWindowFromID(hwnd,IDPB_CONVERTABORT), TRUE);
1243 convertAudioFile(hwnd);
1244 }
1245#endif
1246 /* Start converting image file */
1247 WinPostMsg(hwnd, WM_APPTERMINATENOTIFY, MPFROMLONG(MSG_CONVERTPERCENT), MPFROMLONG(0));
1248 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTOK), FALSE);
1249 WinEnableWindow( WinWindowFromID(hwnd,IDPB_IMGCONVERTABORT), TRUE);
1250 convertImageFile(hwnd);
1251 break;
1252 }
1253 default:
1254 break;
1255 }
1256 return (MRESULT) FALSE;
1257 default:
1258 break;
1259 }/* switch */
1260
1261 return WinDefDlgProc( hwnd, msg, mp1, mp2);
1262}
1263
1264int main (int argc, char *argv[])
1265{
1266 HAB hab;
1267 HMQ hmq;
1268 short a;
1269
1270 /* Create a copy of the args */
1271 /* argv[0]: progname
1272 * argv[1]: imgfile
1273 * argv[2]: IO proc name
1274 */
1275
1276 numArgs=argc;
1277
1278 // sprintf(text,"");
1279 for(a=0;a<argc;a++)
1280 {
1281 params[a]=argv[a];
1282 }
1283
1284 hab=WinInitialize(0);
1285 if(hab) {
1286 hmq=WinCreateMsgQueue(hab,0);
1287 if(hmq) {
1288 /* Check if user started prog by hand */
1289 if(argc<NUMPARAMS-1) {/* Not the right num of params */
1290 pmUsage();
1291 }
1292 else {
1293 /* Save source name */
1294 strcpy(chrSourceName,params[1]);
1295 if(argc==NUMPARAMS)
1296 strcpy(chrProcName,params[2]);
1297 else {
1298 bNoProcGiven=TRUE;
1299 strcpy(chrProcName, "");
1300 }
1301 /* Get our ressource dll */
1302 // RESSOURCEHANDLE=0;
1303 RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
1304
1305 HlpBuildMMProgIniFileName(argv[0], chrIniFile, sizeof(chrIniFile));
1306 /* Register the percent bar window class */
1307 percentRegisterBarClass();
1308
1309 globalHab=WinQueryAnchorBlock(HWND_DESKTOP);
1310 hBitmap=loadBitmap ( chrSourceName, &bmpInfoHeader2);
1311
1312 if( WinDlgBox( HWND_DESKTOP, NULLHANDLE, decodeStatusDialogProc,
1313 RESSOURCEHANDLE, IDDLG_IMGCONVERT, 0) == DID_ERROR )
1314 {
1315 char text[CCHMAXPATH];
1316 char title[CCHMAXPATH];
1317 /*
1318 Text:
1319 Title: "Installation problem"
1320 */
1321 messageBox( text, IDSTR_CONVERTDIALOGERROR , sizeof(text),
1322 title, IDSTR_INSTALLERRORTITLE , sizeof(title),
1323 RESSOURCEHANDLE, HWND_DESKTOP, MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE);
1324
1325 if(hBitmap)
1326 GpiDeleteBitmap(hBitmap);
1327 freeResHandle();
1328 WinDestroyMsgQueue( hmq );
1329 WinTerminate( hab );
1330 DosBeep(100,600);
1331 return( 1 );
1332 }
1333 if(pMemFormatInfo)
1334 free(pMemFormatInfo);
1335 if(hBitmap)
1336 GpiDeleteBitmap(hBitmap);
1337 }
1338 freeResHandle();
1339 WinDestroyMsgQueue(hmq);
1340 }
1341 WinTerminate(hab);
1342 }
1343 return 0;
1344}
Note: See TracBrowser for help on using the repository browser.