source: trunk/classes/mm-progs/imageconverter/imgconv.c@ 219

Last change on this file since 219 was 219, checked in by gyoung, 3 months ago

Add help to the audio and image converter dialogs

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