| 1 | /**************************************************************************
|
|---|
| 2 | * File name : MMBrowse.c
|
|---|
| 3 | *
|
|---|
| 4 | * Description: This application serves as a template than can be use to demonstrate the
|
|---|
| 5 | * use of the MultiMedia I/O subsytem (MMIO).
|
|---|
| 6 | *
|
|---|
| 7 | * This source file contains the following functions:
|
|---|
| 8 | *
|
|---|
| 9 | * GetBitMap(HWND, PSZ)
|
|---|
| 10 | * GetFOURCCDialogProc ( HWND, ULONG, MPARAM, MPARAM )
|
|---|
| 11 | * FixSysMenu(HWND);
|
|---|
| 12 | * AboutDlgProc(HWND, ULONG, MPARAM, MPARAM);
|
|---|
| 13 | * DisplayImageFile ( HWND, PSZ );
|
|---|
| 14 | * DisplayMessageBox ( HWND, USHORT, USHORT, USHORT );
|
|---|
| 15 | * OpenFileDialog ( HWND, PSZ, PSZ, PSZ, PSZ );
|
|---|
| 16 | * FourccToString( FOURCC, PSZ );
|
|---|
| 17 | * MakeItBusy ( BOOL );
|
|---|
| 18 | * Main ( int argc, char *argv[], char *envp[] );
|
|---|
| 19 | * DrawBitMap ( HWND );
|
|---|
| 20 | * CenterDialog ( HWND );
|
|---|
| 21 | * FixSysMenu (HWND);
|
|---|
| 22 | * LoadBitmap (HAB, HDC, HPS *, PSZ );
|
|---|
| 23 | * InitializeHelp ( HWND);
|
|---|
| 24 | * MyWindowProc(hwnd, msg, mp1, mp2)
|
|---|
| 25 | * MessageBox(hwnd idMsg, fsStyle, fBeep)
|
|---|
| 26 | * MainCommand(mp1, mp2)
|
|---|
| 27 | *
|
|---|
| 28 | * Concepts : MMIO IOProcs
|
|---|
| 29 | *
|
|---|
| 30 | * API's : mmioClose
|
|---|
| 31 | * mmioWrite
|
|---|
| 32 | * mmioRead
|
|---|
| 33 | * mmioGetHeader
|
|---|
| 34 | * mmioSetHeader
|
|---|
| 35 | * mmioQueryHeaderLength
|
|---|
| 36 | * mmioSendMessage
|
|---|
| 37 | * mmioOpen
|
|---|
| 38 | * mmioGetFormats
|
|---|
| 39 | * mmioQueryFormatCount
|
|---|
| 40 | * mmioInstallIOProc
|
|---|
| 41 | * mmioStringToFOURCC
|
|---|
| 42 | * mmioIdentifyFile
|
|---|
| 43 | * mmioIniFileHandler
|
|---|
| 44 | * mmioFOURCC
|
|---|
| 45 | *
|
|---|
| 46 | * Files : MMBrowse.c MMBrowse.h MMBrowse.rc MMbrowse.ipf
|
|---|
| 47 | *
|
|---|
| 48 | * Copyright (C) 1991 IBM Corporation
|
|---|
| 49 | *
|
|---|
| 50 | * DISCLAIMER OF WARRANTIES. The following [enclosed] code is
|
|---|
| 51 | * sample code created by IBM Corporation. This sample code is not
|
|---|
| 52 | * part of any standard or IBM product and is provided to you solely
|
|---|
| 53 | * for the purpose of assisting you in the development of your
|
|---|
| 54 | * applications. The code is provided "AS IS", without
|
|---|
| 55 | * warranty of any kind. IBM shall not be liable for any damages
|
|---|
| 56 | * arising out of your use of the sample code, even if they have been
|
|---|
| 57 | * advised of the possibility of such damages. *
|
|---|
| 58 | *************************************************************************/
|
|---|
| 59 | #define INCL_DOSERRORS
|
|---|
| 60 | #define INCL_DOSMODULEMGR
|
|---|
| 61 | #define INCL_DOSPROCESS
|
|---|
| 62 | #define INCL_DOSSEMAPHORES
|
|---|
| 63 | #define INCL_DOSMEMMGR
|
|---|
| 64 | #define INCL_GPI
|
|---|
| 65 | #define INCL_GPICONTROL
|
|---|
| 66 | #define INCL_GPILCIDS
|
|---|
| 67 | #define INCL_GPIMETAFILES
|
|---|
| 68 | #define INCL_GPIPRIMITIVES
|
|---|
| 69 | #define INCL_GPIREGIONS
|
|---|
| 70 | #define INCL_PM
|
|---|
| 71 | #define INCL_WIN
|
|---|
| 72 | #define INCL_WINDIALOGS
|
|---|
| 73 | #define INCL_WINERRORS
|
|---|
| 74 | #define INCL_WINFRAMEMGR
|
|---|
| 75 | #define INCL_WINHELP
|
|---|
| 76 | #define INCL_WINMENUS
|
|---|
| 77 | #define INCL_WINMESSAGEMGR
|
|---|
| 78 | #define INCL_WINMLE
|
|---|
| 79 | #define INCL_WINPOINTERS
|
|---|
| 80 | #define INCL_WINSTDDLGS
|
|---|
| 81 | #define INCL_WINSTDFILE
|
|---|
| 82 | #define INCL_WINSTDSLIDER
|
|---|
| 83 | #define INCL_WINSWITCHLIST
|
|---|
| 84 | #define INCL_WINSYS
|
|---|
| 85 | #define INCL_WINTIMER
|
|---|
| 86 | #define INCL_WINWINDOWMGR
|
|---|
| 87 | #define INCL_REXXSAA
|
|---|
| 88 |
|
|---|
| 89 | #include <os2.h>
|
|---|
| 90 | #include <stdio.h>
|
|---|
| 91 | #include <string.h>
|
|---|
| 92 | #include <malloc.h>
|
|---|
| 93 | #include <rexxsaa.h> /* needed for Rexx */
|
|---|
| 94 | #include "mmbrowse.h"
|
|---|
| 95 | #include "framecontrol.h"
|
|---|
| 96 | #include "mmioos2.h"
|
|---|
| 97 |
|
|---|
| 98 | extern PFNWP g_pfnwpOrgFrameProc;
|
|---|
| 99 | extern FRAMECTRLDATA fcd;
|
|---|
| 100 | char g_binDir[CCHMAXPATH]={0};
|
|---|
| 101 | ULONG ulHeight=40; /* Height of top frame control */
|
|---|
| 102 |
|
|---|
| 103 | MMIMAGEHEADER mmImgHdr; /* Header of loaded image */
|
|---|
| 104 |
|
|---|
| 105 | #if 0
|
|---|
| 106 | char chrMMImageKnownExt[320]={0};/* Array holding the extensions we have a class for e.g. JPG. This
|
|---|
| 107 | array will be filled using an external REXX script. Space for
|
|---|
| 108 | 80 ext should be enough for now (4 bytes per ext e.g.: "JPG "<- note the space) */
|
|---|
| 109 | char chrMMImageExt[200]={0};/* Array holding the extensions for wpclsQueryInstanceFilter(). Will be
|
|---|
| 110 | filled during processing of wpclsInitData() */
|
|---|
| 111 | #endif
|
|---|
| 112 |
|
|---|
| 113 | char pszImageFile[CCHMAXPATH]={0};
|
|---|
| 114 | HBITMAP hbmBitmap=NULLHANDLE;
|
|---|
| 115 |
|
|---|
| 116 | MRESULT EXPENTRY fnwpFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
|
|---|
| 117 |
|
|---|
| 118 | BOOL getStringFromRexxScript(PSZ rexxFile, char* chrResult, ULONG ulSize)
|
|---|
| 119 | {
|
|---|
| 120 |
|
|---|
| 121 | RXSTRING arg[1]; /* argument string for REXX */
|
|---|
| 122 | RXSTRING rexxretval; /* return value from REXX */
|
|---|
| 123 | APIRET rc; /* return code from REXX */
|
|---|
| 124 | SHORT rexxrc = 0; /* return code from function */
|
|---|
| 125 | char theScript[CCHMAXPATH];
|
|---|
| 126 | /* By setting the strlength of the output RXSTRING to zero, we */
|
|---|
| 127 | /* force the interpreter to allocate memory and return it to us. */
|
|---|
| 128 | /* We could provide a buffer for the interpreter to use instead. */
|
|---|
| 129 | rexxretval.strlength = 0L; /* initialize return to empty*/
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | sprintf(theScript, "%s\\%s", g_binDir, rexxFile);
|
|---|
| 133 |
|
|---|
| 134 | /*TRY_LOUD(RX_START) {*/
|
|---|
| 135 | /* Here we call the interpreter. We don't really need to use */
|
|---|
| 136 | /* all the casts in this call; they just help illustrate */
|
|---|
| 137 | /* the data types used. */
|
|---|
| 138 | rc=RexxStart((LONG) 0, /* number of arguments */
|
|---|
| 139 | (PRXSTRING) &arg, /* array of arguments */
|
|---|
| 140 | (PSZ) theScript,/* name of REXX file */
|
|---|
| 141 | (PRXSTRING) 0, /* No INSTORE used */
|
|---|
| 142 | (PSZ) "CWRXX", /* Command env. name */
|
|---|
| 143 | (LONG) RXSUBROUTINE, /* Code for how invoked */
|
|---|
| 144 | (PRXSYSEXIT) 0, /* No EXITs on this call */
|
|---|
| 145 | (PSHORT) &rexxrc, /* Rexx program output */
|
|---|
| 146 | (PRXSTRING) &rexxretval ); /* Rexx program output */
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 | #if 0
|
|---|
| 150 | if(rc) {
|
|---|
| 151 | sprintf(text,"Error in the Rexx skript %s\n\n Get more information with 'help REX%04d'.\n",
|
|---|
| 152 | tPt->rexxSkript, rc*-1);
|
|---|
| 153 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE|MB_ERROR);
|
|---|
| 154 | }
|
|---|
| 155 | #endif
|
|---|
| 156 | if(!rc) {
|
|---|
| 157 | if(ulSize>rexxretval.strlength) {
|
|---|
| 158 | strncpy(chrResult, rexxretval.strptr, rexxretval.strlength);
|
|---|
| 159 | chrResult[rexxretval.strlength]=0;
|
|---|
| 160 | }
|
|---|
| 161 | else
|
|---|
| 162 | strncpy(chrResult, rexxretval.strptr, ulSize);
|
|---|
| 163 | chrResult[ulSize-1]=0;
|
|---|
| 164 | }
|
|---|
| 165 | if(rexxretval.strptr)
|
|---|
| 166 | DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */
|
|---|
| 167 | /* }
|
|---|
| 168 | CATCH(RX_START)
|
|---|
| 169 | {}END_CATCH;*/
|
|---|
| 170 | return TRUE;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | /****************************************************************************/
|
|---|
| 175 | /* */
|
|---|
| 176 | /* This procedure handles the frame extension of the frame at the top */
|
|---|
| 177 | /* */
|
|---|
| 178 | /* */
|
|---|
| 179 | /****************************************************************************/
|
|---|
| 180 | MRESULT EXPENTRY topCtrlDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 181 | {
|
|---|
| 182 |
|
|---|
| 183 | switch(msg)
|
|---|
| 184 | {
|
|---|
| 185 | /*****************************************************/
|
|---|
| 186 | /* Init the dialog */
|
|---|
| 187 | /*****************************************************/
|
|---|
| 188 | case WM_INITDLG :
|
|---|
| 189 | {
|
|---|
| 190 | ULONG ulStyle;
|
|---|
| 191 | SWP swp;
|
|---|
| 192 |
|
|---|
| 193 | WinSetWindowULong(hwnd,QWL_USER,(ULONG)PVOIDFROMMP(mp2));//Save object ptr.
|
|---|
| 194 | WinQueryWindowPos(WinQueryWindow(hwnd,QW_PARENT),&swp);
|
|---|
| 195 | #if 0
|
|---|
| 196 | /* Set dialog font to WarpSans for Warp 4 and above */
|
|---|
| 197 | if(cwQueryOSRelease()>=40) {
|
|---|
| 198 | WinSetPresParam(hwnd,
|
|---|
| 199 | PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
|
|---|
| 200 | DEFAULT_DIALOG_FONT );
|
|---|
| 201 | }
|
|---|
| 202 | #endif
|
|---|
| 203 | return (MRESULT)FALSE;
|
|---|
| 204 | }
|
|---|
| 205 | #if 0
|
|---|
| 206 | case WM_CHAR:
|
|---|
| 207 | // Set focus to container so the key will be processed as usual
|
|---|
| 208 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),FID_CLIENT));
|
|---|
| 209 | return WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT),FID_CLIENT),msg,mp1,mp2);
|
|---|
| 210 |
|
|---|
| 211 | /*****************************************************/
|
|---|
| 212 | /* Paint the background. */
|
|---|
| 213 | /*****************************************************/
|
|---|
| 214 | case WM_PAINT:
|
|---|
| 215 | {
|
|---|
| 216 | HPS hps;
|
|---|
| 217 | RECTL rcl, rclSave, rclSource;
|
|---|
| 218 | SWP swp;
|
|---|
| 219 |
|
|---|
| 220 | hps=WinBeginPaint(hwnd, NULLHANDLE,NULL);
|
|---|
| 221 | /* Get Window size */
|
|---|
| 222 | WinQueryWindowRect(hwnd, &rcl);
|
|---|
| 223 | rclSave=rcl;
|
|---|
| 224 | /* Get size and pos of control area */
|
|---|
| 225 | WinQueryWindowPos(WinWindowFromID(hwnd, IDDLG_TOPMIDDLE),&swp);
|
|---|
| 226 | /* Left area */
|
|---|
| 227 | rcl.xRight=swp.x;
|
|---|
| 228 | rclSource.xLeft=0;
|
|---|
| 229 | rclSource.yBottom=0;
|
|---|
| 230 | rclSource.yTop=allBMPs[CTRLIDX_TOPLEFT].bmpInfoHdr.cy;
|
|---|
| 231 | rclSource.xRight=allBMPs[CTRLIDX_TOPLEFT].bmpInfoHdr.cx;
|
|---|
| 232 | WinDrawBitmap(hps, allBMPs[CTRLIDX_TOPLEFT].hbm,
|
|---|
| 233 | &rclSource,
|
|---|
| 234 | (PPOINTL)&rclSave,
|
|---|
| 235 | 0, 0,
|
|---|
| 236 | DBM_IMAGEATTRS | DBM_STRETCH);
|
|---|
| 237 |
|
|---|
| 238 | /* Right area */
|
|---|
| 239 | rclSave.xLeft=swp.x+swp.cx;
|
|---|
| 240 | rclSource.xLeft=0;
|
|---|
| 241 | rclSource.yBottom=0;
|
|---|
| 242 | rclSource.yTop=allBMPs[CTRLIDX_TOPRIGHT].bmpInfoHdr.cy;
|
|---|
| 243 | rclSource.xRight=allBMPs[CTRLIDX_TOPRIGHT].bmpInfoHdr.cx;
|
|---|
| 244 | WinDrawBitmap(hps, allBMPs[CTRLIDX_TOPRIGHT].hbm,
|
|---|
| 245 | &rclSource,
|
|---|
| 246 | (PPOINTL)&rclSave,
|
|---|
| 247 | 0, 0,
|
|---|
| 248 | DBM_IMAGEATTRS | DBM_STRETCH);
|
|---|
| 249 |
|
|---|
| 250 | WinEndPaint(hps);
|
|---|
| 251 | return (MRESULT) 0;
|
|---|
| 252 | }
|
|---|
| 253 | #endif
|
|---|
| 254 | default:
|
|---|
| 255 | break;
|
|---|
| 256 | }
|
|---|
| 257 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | VOID main ( int argc, char *argv[], char *envp[] )
|
|---|
| 262 | {
|
|---|
| 263 | HMQ hmq; /* Message queue handle */
|
|---|
| 264 | HWND hwndClient; /* Client area window handle */
|
|---|
| 265 | HWND hwndFrame; /* Frame window handle */
|
|---|
| 266 | QMSG qmsg; /* Message from message queue */
|
|---|
| 267 | ULONG flCreate; /* Window creation control flags*/
|
|---|
| 268 | BOOL bReturnCode;
|
|---|
| 269 | SWCNTRL swcntrl; /* struct with Task Mgr info */
|
|---|
| 270 | FRAMECTRLDATA *pfcd;
|
|---|
| 271 | char * chrPtr;
|
|---|
| 272 |
|
|---|
| 273 | FRAMECDATA framecd={0};
|
|---|
| 274 |
|
|---|
| 275 | strcpy(g_binDir, argv[0]);
|
|---|
| 276 | if((chrPtr=strrchr(g_binDir, '\\'))!=NULLHANDLE)
|
|---|
| 277 | *chrPtr=0;
|
|---|
| 278 |
|
|---|
| 279 | if(argc >1)
|
|---|
| 280 | strcpy(pszImageFile, argv[1]);
|
|---|
| 281 |
|
|---|
| 282 | hab = WinInitialize( 0 ); /* Initialize PM */
|
|---|
| 283 |
|
|---|
| 284 | hmq = WinCreateMsgQueue( hab, 0 ); /* Create a message queue */
|
|---|
| 285 |
|
|---|
| 286 | bReturnCode = WinRegisterClass( hab,
|
|---|
| 287 | "MMBrowser",
|
|---|
| 288 | (PFNWP) MyWindowProc,
|
|---|
| 289 | CS_SIZEREDRAW,
|
|---|
| 290 | 0 );
|
|---|
| 291 |
|
|---|
| 292 | flCreate = (FCF_HORZSCROLL| FCF_VERTSCROLL| FCF_STANDARD) & ~FCF_SHELLPOSITION;
|
|---|
| 293 |
|
|---|
| 294 | hwndFrame = WinCreateStdWindow ( HWND_DESKTOP,
|
|---|
| 295 | 0L,
|
|---|
| 296 | &flCreate,
|
|---|
| 297 | "MMBrowser",
|
|---|
| 298 | "",
|
|---|
| 299 | 0L,
|
|---|
| 300 | 0,
|
|---|
| 301 | ID_WINDOW,
|
|---|
| 302 | &hwndClient );
|
|---|
| 303 |
|
|---|
| 304 | g_pfnwpOrgFrameProc=WinSubclassWindow(hwndFrame, fnwpFrameProc);
|
|---|
| 305 |
|
|---|
| 306 | pfcd=&fcd;
|
|---|
| 307 | pfcd->hwndCtlTop=WinLoadDlg(hwndFrame, hwndFrame, topCtrlDialogProc, hResource, IDDLG_TOPFRAME ,0);
|
|---|
| 308 |
|
|---|
| 309 | if(pfcd->hwndCtlTop)
|
|---|
| 310 | {
|
|---|
| 311 | RECTL rectl;
|
|---|
| 312 |
|
|---|
| 313 | /* Query the size of the dialog */
|
|---|
| 314 | WinQueryWindowRect(pfcd->hwndCtlTop,&rectl);
|
|---|
| 315 |
|
|---|
| 316 | pfcd->bTop=TRUE;
|
|---|
| 317 | pfcd->sizelTopFrame.cx=100;
|
|---|
| 318 | // pfcd->sizelTopFrame.cy=rectl.yTop;
|
|---|
| 319 | pfcd->sizelTopFrame.cy=ulHeight;
|
|---|
| 320 | pfcd->ulFlagsTop=0;
|
|---|
| 321 | // WinSendMsg(hwndFolder,WM_UPDATEFRAME,0,0);
|
|---|
| 322 | }
|
|---|
| 323 | #if 0
|
|---|
| 324 | /* Scrollbars */
|
|---|
| 325 | framecd.cb=sizeof(FRAMECDATA);
|
|---|
| 326 | framecd.flCreateFlags=FCF_HORZSCROLL;
|
|---|
| 327 | WinCreateFrameControls(hwndFrame, &framecd, NULLHANDLE);
|
|---|
| 328 | #endif
|
|---|
| 329 |
|
|---|
| 330 | bReturnCode = WinSetWindowPos( hwndFrame,
|
|---|
| 331 | HWND_TOP,
|
|---|
| 332 | 100, 100, 400, 280,
|
|---|
| 333 | SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW );
|
|---|
| 334 |
|
|---|
| 335 | memset(&swcntrl, 0, sizeof(SWCNTRL)); /* init structure */
|
|---|
| 336 |
|
|---|
| 337 | swcntrl.hwnd = hwndFrame;
|
|---|
| 338 | strcpy(swcntrl.szSwtitle, "MMBrowser" );
|
|---|
| 339 |
|
|---|
| 340 | WinAddSwitchEntry((PSWCNTRL)&swcntrl); /* add app to Task Mgr */
|
|---|
| 341 | InitializeHelp (hwndFrame );
|
|---|
| 342 |
|
|---|
| 343 | /*
|
|---|
| 344 | * Now, dispatch all messages...
|
|---|
| 345 | */
|
|---|
| 346 | while( WinGetMsg( hab, &qmsg, 0, 0, 0 ) )
|
|---|
| 347 | {
|
|---|
| 348 | WinDispatchMsg( hab, &qmsg );
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | WinDestroyHelpInstance(hwndHelpInstance);
|
|---|
| 352 | WinDestroyWindow( hwndFrame );
|
|---|
| 353 | WinDestroyMsgQueue( hmq );
|
|---|
| 354 | WinTerminate( hab );
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | /*********************************************************/
|
|---|
| 358 | /* */
|
|---|
| 359 | /*********************************************************/
|
|---|
| 360 | VOID MakeItBusy ( BOOL BusyStatus )
|
|---|
| 361 | {
|
|---|
| 362 | if( BusyStatus == TRUE )
|
|---|
| 363 | {
|
|---|
| 364 | WinSetPointer ( HWND_DESKTOP,
|
|---|
| 365 | WinQuerySysPointer ( HWND_DESKTOP,
|
|---|
| 366 | SPTR_WAIT,
|
|---|
| 367 | FALSE));
|
|---|
| 368 | }
|
|---|
| 369 | else
|
|---|
| 370 | {
|
|---|
| 371 | WinSetPointer ( HWND_DESKTOP,
|
|---|
| 372 | WinQuerySysPointer ( HWND_DESKTOP,
|
|---|
| 373 | SPTR_ARROW,
|
|---|
| 374 | FALSE));
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 | /*********************************************************/
|
|---|
| 381 | /* */
|
|---|
| 382 | /*********************************************************/
|
|---|
| 383 | MRESULT EXPENTRY MyWindowProc ( HWND hwnd,
|
|---|
| 384 | USHORT msg,
|
|---|
| 385 | MPARAM mp1,
|
|---|
| 386 | MPARAM mp2 )
|
|---|
| 387 | {
|
|---|
| 388 | USHORT command;
|
|---|
| 389 | BOOL bReturnCode;
|
|---|
| 390 | ULONG ReturnCode;
|
|---|
| 391 | PMMINIFILEINFO pmmIniFileInfo;
|
|---|
| 392 | FOURCC IOProcFourCC;
|
|---|
| 393 | FOURCC IOProcFourSource;
|
|---|
| 394 | FOURCC IOProcFourTarget;
|
|---|
| 395 | ULONG ulIndex = 0;
|
|---|
| 396 | CHAR szTempBuffer1[STRING_LENGTH];
|
|---|
| 397 | CHAR szTempBuffer2[STRING_LENGTH];
|
|---|
| 398 | FOURCC fccIOProc;
|
|---|
| 399 | FOURCC fccSourceIOProc;
|
|---|
| 400 | MMFORMATINFO mmFormatInfoSource;
|
|---|
| 401 | MMFORMATINFO mmFormatInfoTarget;
|
|---|
| 402 |
|
|---|
| 403 | switch( msg )
|
|---|
| 404 | {
|
|---|
| 405 | #if 0
|
|---|
| 406 | case DM_DRAGOVER:
|
|---|
| 407 | {
|
|---|
| 408 | PDRAGINFO pdi=PVOIDFROMMP(mp1);
|
|---|
| 409 |
|
|---|
| 410 | if(DrgAccessDraginfo(pdi))
|
|---|
| 411 | {
|
|---|
| 412 | USHORT usOp;
|
|---|
| 413 | USHORT usItems=DrgQueryDragitemCount(pdi);
|
|---|
| 414 | int i;
|
|---|
| 415 | PDRAGITEM dragItem;
|
|---|
| 416 |
|
|---|
| 417 | for(i=0;i<usItems; i++)
|
|---|
| 418 | {
|
|---|
| 419 | char text[300];
|
|---|
| 420 | dragItem=DrgQueryDragitemPtr(pdi, i);
|
|---|
| 421 | DrgQueryStrName(dragItem->hstrType,sizeof(text), text);
|
|---|
| 422 | WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), text);
|
|---|
| 423 | if(!DrgVerifyRMF(dragItem, "DRM_OS2FILE", NULLHANDLE)) {
|
|---|
| 424 | //DosBeep(5000, 100);
|
|---|
| 425 | break;
|
|---|
| 426 | }
|
|---|
| 427 | }
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 | #if 0
|
|---|
| 431 | switch(pdi->usOperation)
|
|---|
| 432 | {
|
|---|
| 433 |
|
|---|
| 434 | }
|
|---|
| 435 | #endif
|
|---|
| 436 | //DosBeep(500, 100);
|
|---|
| 437 | DrgFreeDraginfo(pdi);
|
|---|
| 438 | }
|
|---|
| 439 | return MRFROM2SHORT(DOR_NEVERDROP, DO_COPY);
|
|---|
| 440 | }
|
|---|
| 441 | #endif
|
|---|
| 442 | case WM_CREATE:
|
|---|
| 443 |
|
|---|
| 444 | // _getMMImageExt();
|
|---|
| 445 | // WinSetWindowText(WinQueryWindow(hwnd, QW_PARENT), chrMMImageKnownExt);
|
|---|
| 446 |
|
|---|
| 447 | /*
|
|---|
| 448 | * Get the open dialog title from resource file.
|
|---|
| 449 | */
|
|---|
| 450 | WinLoadString( hab,
|
|---|
| 451 | 0,
|
|---|
| 452 | IDS_OPEN_DIALOG_TITLE,
|
|---|
| 453 | STRING_LENGTH,
|
|---|
| 454 | szOpenDialogTitle ) ;
|
|---|
| 455 |
|
|---|
| 456 | /*
|
|---|
| 457 | * Get the open dialog file extension from resource file.
|
|---|
| 458 | */
|
|---|
| 459 | WinLoadString( hab,
|
|---|
| 460 | 0,
|
|---|
| 461 | IDS_OPEN_DIALOG_FILE_EXT,
|
|---|
| 462 | STRING_LENGTH,
|
|---|
| 463 | szOpenDialogFileExt );
|
|---|
| 464 |
|
|---|
| 465 | /*
|
|---|
| 466 | * Get the open ok button from resource file.
|
|---|
| 467 | */
|
|---|
| 468 | WinLoadString( hab,
|
|---|
| 469 | 0,
|
|---|
| 470 | IDS_OPEN_OK_BUTTON,
|
|---|
| 471 | STRING_LENGTH,
|
|---|
| 472 | szOpenOKButton );
|
|---|
| 473 |
|
|---|
| 474 | /*
|
|---|
| 475 | * Get the install ok button from resource file.
|
|---|
| 476 | */
|
|---|
| 477 | WinLoadString( hab,
|
|---|
| 478 | 0,
|
|---|
| 479 | IDS_INSTALL_OK_BUTTON,
|
|---|
| 480 | STRING_LENGTH,
|
|---|
| 481 | szInstallOKButton );
|
|---|
| 482 |
|
|---|
| 483 | /*
|
|---|
| 484 | * Get the install dialog box title from resource file.
|
|---|
| 485 | */
|
|---|
| 486 | WinLoadString( hab,
|
|---|
| 487 | 0,
|
|---|
| 488 | IDS_INSTALL_TITLE,
|
|---|
| 489 | STRING_LENGTH,
|
|---|
| 490 | szInstallTitle );
|
|---|
| 491 |
|
|---|
| 492 | /*
|
|---|
| 493 | * Get the install dialog box file extension from resource file.
|
|---|
| 494 | */
|
|---|
| 495 | WinLoadString( hab,
|
|---|
| 496 | 0,
|
|---|
| 497 | IDS_INSTALL_FILE_EXT,
|
|---|
| 498 | STRING_LENGTH,
|
|---|
| 499 | szInstallFileExt );
|
|---|
| 500 |
|
|---|
| 501 | /*
|
|---|
| 502 | * Copy the IO Proc standard name from resource file.
|
|---|
| 503 | */
|
|---|
| 504 | WinLoadString( hab,
|
|---|
| 505 | 0,
|
|---|
| 506 | IDS_IOPROC_NAME,
|
|---|
| 507 | STRING_LENGTH,
|
|---|
| 508 | szIOProcName );
|
|---|
| 509 |
|
|---|
| 510 | hbmBitmap = GetBitMap ( hwnd, pszImageFile );
|
|---|
| 511 |
|
|---|
| 512 | break; // end of WM_CREATE
|
|---|
| 513 |
|
|---|
| 514 | case WM_HELP :
|
|---|
| 515 | WinSendMsg ( hwndHelpInstance,
|
|---|
| 516 | HM_DISPLAY_HELP,
|
|---|
| 517 | MPFROMLONG ( 1 ),
|
|---|
| 518 | MPFROMSHORT ( HM_RESOURCEID ) );
|
|---|
| 519 |
|
|---|
| 520 | return( 0 );
|
|---|
| 521 | break;
|
|---|
| 522 |
|
|---|
| 523 | case WM_ERASEBACKGROUND:
|
|---|
| 524 | return ( MRFROMLONG ( TRUE ) );
|
|---|
| 525 | break;
|
|---|
| 526 |
|
|---|
| 527 | case WM_COMMAND:
|
|---|
| 528 | command = SHORT1FROMMP(mp1); /* Extract the command value */
|
|---|
| 529 | switch (command)
|
|---|
| 530 | {
|
|---|
| 531 | /*
|
|---|
| 532 | * Open a file (read and view)
|
|---|
| 533 | */
|
|---|
| 534 | case ID_FILE_OPEN:
|
|---|
| 535 | /*
|
|---|
| 536 | * Get filename from user to open
|
|---|
| 537 | */
|
|---|
| 538 | if( pszImageFile == NULL )
|
|---|
| 539 | {
|
|---|
| 540 | break;
|
|---|
| 541 | }
|
|---|
| 542 | if( OpenFileDialog ( hwnd, // handle of owner window
|
|---|
| 543 | szOpenDialogTitle, // title of open dialog box
|
|---|
| 544 | "*.*", // file extension
|
|---|
| 545 | szOpenOKButton,
|
|---|
| 546 | pszImageFile ) == FALSE ) // return filename here.
|
|---|
| 547 | {
|
|---|
| 548 | break;
|
|---|
| 549 | // error.
|
|---|
| 550 | }
|
|---|
| 551 |
|
|---|
| 552 | hbmBitmap = (BOOL) GetBitMap ( hwnd, pszImageFile );
|
|---|
| 553 |
|
|---|
| 554 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 555 | break;
|
|---|
| 556 | case ID_FILE_SAVEAS:
|
|---|
| 557 | if( mmioIdentifyFile(pszImageFile,
|
|---|
| 558 | 0L,
|
|---|
| 559 | &mmFormatInfoSource,
|
|---|
| 560 | &IOProcFourSource,
|
|---|
| 561 | 0L,
|
|---|
| 562 | 0L))
|
|---|
| 563 | {
|
|---|
| 564 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 565 | HWND_DESKTOP,
|
|---|
| 566 | "Please Open an Image File",
|
|---|
| 567 | "Save as .....",
|
|---|
| 568 | (HMODULE) NULL,
|
|---|
| 569 | (ULONG) MB_OK | MB_MOVEABLE |
|
|---|
| 570 | MB_ERROR );
|
|---|
| 571 | break;
|
|---|
| 572 | }
|
|---|
| 573 | fccSourceIOProc = mmFormatInfoSource.fccIOProc;
|
|---|
| 574 | SaveFile( hwnd, pszImageFile, fccSourceIOProc);
|
|---|
| 575 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 576 | break;
|
|---|
| 577 |
|
|---|
| 578 | case IDM_HELPUSINGHELP:
|
|---|
| 579 | if ( WinSendMsg ( hwndHelpInstance,
|
|---|
| 580 | HM_DISPLAY_HELP,
|
|---|
| 581 | MPVOID,
|
|---|
| 582 | MPVOID ) )
|
|---|
| 583 | {
|
|---|
| 584 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 585 | hwnd,
|
|---|
| 586 | "Cannot display Help For Help.",
|
|---|
| 587 | "Help For Help",
|
|---|
| 588 | (HMODULE) NULL,
|
|---|
| 589 | MB_OK | MB_ERROR );
|
|---|
| 590 | }
|
|---|
| 591 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 592 | break;
|
|---|
| 593 |
|
|---|
| 594 | case IDM_HELPGENERAL:
|
|---|
| 595 | if ( WinSendMsg ( hwndHelpInstance,
|
|---|
| 596 | HM_DISPLAY_HELP,
|
|---|
| 597 | MPFROM2SHORT(PANEL_HELPGENERAL,NULL), MPFROMSHORT(HM_RESOURCEID)))
|
|---|
| 598 | {
|
|---|
| 599 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 600 | break;
|
|---|
| 601 | }
|
|---|
| 602 | break;
|
|---|
| 603 | case IDM_HELPINDEX:
|
|---|
| 604 | if (WinSendMsg ( hwndHelpInstance,
|
|---|
| 605 | HM_HELP_INDEX,
|
|---|
| 606 | MPVOID,
|
|---|
| 607 | MPVOID))
|
|---|
| 608 | {
|
|---|
| 609 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 610 | hwnd,
|
|---|
| 611 | "Cannot display Help Index.",
|
|---|
| 612 | "Help Index",
|
|---|
| 613 | (HMODULE) NULL,
|
|---|
| 614 | MB_OK | MB_ERROR );
|
|---|
| 615 | }
|
|---|
| 616 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 617 | break;
|
|---|
| 618 |
|
|---|
| 619 | case IDM_HELPPRODUCTINFO:
|
|---|
| 620 |
|
|---|
| 621 | WinDlgBox(HWND_DESKTOP,
|
|---|
| 622 | hwnd,
|
|---|
| 623 | (PFNWP)AboutDlgProc,
|
|---|
| 624 | 0,
|
|---|
| 625 | IDD_PRODUCTINFO,
|
|---|
| 626 | (PVOID)NULL);
|
|---|
| 627 |
|
|---|
| 628 | WinInvalidateRegion( hwnd, 0, FALSE );
|
|---|
| 629 | break;
|
|---|
| 630 |
|
|---|
| 631 | /*
|
|---|
| 632 | * Exit from program.
|
|---|
| 633 | */
|
|---|
| 634 |
|
|---|
| 635 | case ID_EXITPROG:
|
|---|
| 636 | WinPostMsg( hwnd, WM_CLOSE, 0L, 0L );
|
|---|
| 637 | break;
|
|---|
| 638 |
|
|---|
| 639 | default:
|
|---|
| 640 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
|---|
| 641 | }
|
|---|
| 642 |
|
|---|
| 643 | break; // end of WM_COMMAND
|
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 | case WM_PAINT:
|
|---|
| 647 |
|
|---|
| 648 | if (!WinIsWindowVisible(hwnd))
|
|---|
| 649 | {
|
|---|
| 650 | return((MRESULT)NULL);
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | /*
|
|---|
| 654 | * Check our Presentation Space. If a bitmap exists,
|
|---|
| 655 | * then display it. Otherwise, do our normal stuff.
|
|---|
| 656 | */
|
|---|
| 657 |
|
|---|
| 658 | if (hpsMemory)
|
|---|
| 659 | {
|
|---|
| 660 | MakeItBusy ( TRUE );
|
|---|
| 661 | DrawBitMap(hwnd);
|
|---|
| 662 | MakeItBusy ( FALSE );
|
|---|
| 663 | }
|
|---|
| 664 |
|
|---|
| 665 | WinDefWindowProc ( hwnd, msg, mp1, mp2 );
|
|---|
| 666 | break;
|
|---|
| 667 | return((MRESULT)TRUE);
|
|---|
| 668 |
|
|---|
| 669 | case WM_CLOSE:
|
|---|
| 670 | WinPostMsg( hwnd, WM_QUIT, 0L, 0L ); /* Cause termination */
|
|---|
| 671 | break;
|
|---|
| 672 | /*
|
|---|
| 673 | * Everything else comes here.
|
|---|
| 674 | */
|
|---|
| 675 |
|
|---|
| 676 | default:
|
|---|
| 677 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | return FALSE;
|
|---|
| 681 | }
|
|---|
| 682 |
|
|---|
| 683 |
|
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 | static char* _getExtFromImageIOProc(BOOL bWrite)
|
|---|
| 687 | {
|
|---|
| 688 | CHAR szBuffer[ sizeof( FOURCC ) + CCHMAXPATH + 4 ];
|
|---|
| 689 | MMFORMATINFO mmFormatInfo;
|
|---|
| 690 | PMMFORMATINFO pmmFormatInfoArray;
|
|---|
| 691 | void * memPtr;
|
|---|
| 692 | ULONG ulReturnCode;
|
|---|
| 693 | LONG lFormatsRead;
|
|---|
| 694 | LONG index;
|
|---|
| 695 | LONG lBytesRead;
|
|---|
| 696 | HWND hwndSubMenu;
|
|---|
| 697 | MENUITEM mi;
|
|---|
| 698 | LONG lNumIOProcs;
|
|---|
| 699 | char * chrMMImageKnownExt=NULLHANDLE;
|
|---|
| 700 |
|
|---|
| 701 | memset( &mmFormatInfo,
|
|---|
| 702 | '\0',
|
|---|
| 703 | sizeof(MMFORMATINFO) );
|
|---|
| 704 |
|
|---|
| 705 | mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
|
|---|
| 706 | if(!bWrite)
|
|---|
| 707 | mmFormatInfo.ulFlags|=MMIO_CANREADTRANSLATED;/* Read !!!*/
|
|---|
| 708 | else
|
|---|
| 709 | mmFormatInfo.ulFlags|=MMIO_CANWRITETRANSLATED;/* Read !!!*/
|
|---|
| 710 | ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
|
|---|
| 711 | &lNumIOProcs,
|
|---|
| 712 | 0,
|
|---|
| 713 | 0 );
|
|---|
| 714 |
|
|---|
| 715 | if( ulReturnCode != MMIO_SUCCESS )
|
|---|
| 716 | {
|
|---|
| 717 | /*
|
|---|
| 718 | * Error - mmioQueryFormatCount failed.
|
|---|
| 719 | */
|
|---|
| 720 | return NULLHANDLE;
|
|---|
| 721 | }
|
|---|
| 722 |
|
|---|
| 723 | /*
|
|---|
| 724 | * Allocate enough memory for n number of FormatInfo blocks
|
|---|
| 725 | */
|
|---|
| 726 | pmmFormatInfoArray = malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
|
|---|
| 727 | memPtr=pmmFormatInfoArray;
|
|---|
| 728 | if( pmmFormatInfoArray == NULL )
|
|---|
| 729 | {
|
|---|
| 730 | /*
|
|---|
| 731 | * Could not allocate enough memory for mmFormatInfo array.
|
|---|
| 732 | */
|
|---|
| 733 | return NULLHANDLE;
|
|---|
| 734 | }
|
|---|
| 735 |
|
|---|
| 736 | /*
|
|---|
| 737 | * call mmioGetFormats to get info on the formats supported.
|
|---|
| 738 | */
|
|---|
| 739 | ulReturnCode = mmioGetFormats( &mmFormatInfo,
|
|---|
| 740 | lNumIOProcs,
|
|---|
| 741 | pmmFormatInfoArray,
|
|---|
| 742 | &lFormatsRead,
|
|---|
| 743 | 0,
|
|---|
| 744 | 0 );
|
|---|
| 745 | if( ulReturnCode != MMIO_SUCCESS )
|
|---|
| 746 | {
|
|---|
| 747 | /*
|
|---|
| 748 | * mmioGetFormats failed.
|
|---|
| 749 | */
|
|---|
| 750 | free(pmmFormatInfoArray);
|
|---|
| 751 | return NULLHANDLE;
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | if( lFormatsRead != lNumIOProcs )
|
|---|
| 755 | {
|
|---|
| 756 | /*
|
|---|
| 757 | * Error in MMIO - number of formats read in by
|
|---|
| 758 | * mmioGetFormats is not equal to number of formats
|
|---|
| 759 | * found by mmioQueryFormatCount.
|
|---|
| 760 | */
|
|---|
| 761 | free(pmmFormatInfoArray);
|
|---|
| 762 | return NULLHANDLE;
|
|---|
| 763 | }
|
|---|
| 764 |
|
|---|
| 765 | #define EXT_MEM_SIZE 10000
|
|---|
| 766 |
|
|---|
| 767 | /* Get extension string. I'm lazy here and just allocate a huge array. */
|
|---|
| 768 | if((chrMMImageKnownExt=malloc(EXT_MEM_SIZE))==NULLHANDLE)
|
|---|
| 769 | return NULLHANDLE;
|
|---|
| 770 |
|
|---|
| 771 | memset(chrMMImageKnownExt, 0, EXT_MEM_SIZE);
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 | for ( index = 0; index <lNumIOProcs; index++ )
|
|---|
| 775 | {
|
|---|
| 776 | /* Now scan the whole image proc array */
|
|---|
| 777 | if(chrMMImageKnownExt[0]==0)
|
|---|
| 778 | strcpy(chrMMImageKnownExt, "*.");/* First extension */
|
|---|
| 779 | else
|
|---|
| 780 | strcat(chrMMImageKnownExt, ";*.");
|
|---|
| 781 |
|
|---|
| 782 | strcat(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt);
|
|---|
| 783 |
|
|---|
| 784 | // HlpWriteToTrapLog("Known Extension: %s\n", chrMMImageKnownExt);
|
|---|
| 785 | // HlpWriteToTrapLog("Extension: %s\n", chrMMImageExt);
|
|---|
| 786 |
|
|---|
| 787 | /*
|
|---|
| 788 | * advance to next entry in mmFormatInfo array
|
|---|
| 789 | */
|
|---|
| 790 | pmmFormatInfoArray++;
|
|---|
| 791 | }
|
|---|
| 792 |
|
|---|
| 793 | free(memPtr);
|
|---|
| 794 |
|
|---|
| 795 | return chrMMImageKnownExt;
|
|---|
| 796 | }
|
|---|
| 797 |
|
|---|
| 798 |
|
|---|
| 799 |
|
|---|
| 800 |
|
|---|
| 801 |
|
|---|
| 802 | /**********************************************************************/
|
|---|
| 803 | /* */
|
|---|
| 804 | /* Name: OpenFileDialog */
|
|---|
| 805 | /* */
|
|---|
| 806 | /* Purpose: open the standard file open dialog as file extention */
|
|---|
| 807 | /* and return the filename */
|
|---|
| 808 | /* */
|
|---|
| 809 | /* Usage: called when the user needs to supply a name for */
|
|---|
| 810 | /* the file to be opened */
|
|---|
| 811 | /* */
|
|---|
| 812 | /* Method: calls the standard file open dialog to get the */
|
|---|
| 813 | /* file name. */
|
|---|
| 814 | /* */
|
|---|
| 815 | /* Parameters: HWD hwnd Handle of the owner window. */
|
|---|
| 816 | /* PSZ szTitle Title of open dialog. */
|
|---|
| 817 | /* PSZ pszFileExt File extention. (for example : *.txt)*/
|
|---|
| 818 | /* PSZ pszFullPath PSZ for returning the file name. */
|
|---|
| 819 | /* */
|
|---|
| 820 | /* Returns: TRUE if successful in getting a file name, FALSE */
|
|---|
| 821 | /* if not in pushing CANCEL */
|
|---|
| 822 | /* PSZ pszFullPath pointer to filename (full path) */
|
|---|
| 823 | /* */
|
|---|
| 824 | /**********************************************************************/
|
|---|
| 825 |
|
|---|
| 826 | BOOL OpenFileDialog(HWND hwndOwner,
|
|---|
| 827 | PSZ szTitle,
|
|---|
| 828 | PSZ szFileExt,
|
|---|
| 829 | PSZ szButton,
|
|---|
| 830 | PSZ szFullPath )
|
|---|
| 831 | {
|
|---|
| 832 | FILEDLG fdg;
|
|---|
| 833 | char *chrExt=NULLHANDLE;
|
|---|
| 834 |
|
|---|
| 835 | memset(&fdg, 0, sizeof(FILEDLG));
|
|---|
| 836 | fdg.cbSize = sizeof(FILEDLG); /* Size of FILEDLG. */
|
|---|
| 837 | fdg.pszTitle = szTitle; /* String to display in title bar. */
|
|---|
| 838 | fdg.pszOKButton = szButton ;
|
|---|
| 839 | fdg.ulUser = 0L; /* User defined field. */
|
|---|
| 840 | fdg.fl = FDS_CENTER |
|
|---|
| 841 | FDS_OPEN_DIALOG;
|
|---|
| 842 | fdg.pfnDlgProc = NULL;
|
|---|
| 843 | fdg.lReturn = 0L; /* Result code from dialog dismissal. */
|
|---|
| 844 | fdg.lSRC = 0L; /* System return code. */
|
|---|
| 845 | fdg.hMod = 0; /* Custom file dialog template. */
|
|---|
| 846 | fdg.usDlgId = 0; /* Custom file dialog ID. */
|
|---|
| 847 | fdg.x = 100; /* X coordinate of the dialog. */
|
|---|
| 848 | fdg.y = 100; /* Y coordinate of the dialog. */
|
|---|
| 849 |
|
|---|
| 850 | chrExt=_getExtFromImageIOProc(FALSE); /* Get image extensions */
|
|---|
| 851 |
|
|---|
| 852 | strcpy( fdg.szFullFile, chrExt);
|
|---|
| 853 | /* set selected fully qualified path */
|
|---|
| 854 | // strcpy( fdg.szFullFile, szFileExt);
|
|---|
| 855 |
|
|---|
| 856 | /* get the file */
|
|---|
| 857 | if ( !WinFileDlg ( HWND_DESKTOP,
|
|---|
| 858 | hwndOwner,
|
|---|
| 859 | (PFILEDLG)&fdg ) ) {
|
|---|
| 860 | if(chrExt)
|
|---|
| 861 | free(chrExt);
|
|---|
| 862 | return FALSE;
|
|---|
| 863 | }
|
|---|
| 864 |
|
|---|
| 865 | if(chrExt)
|
|---|
| 866 | free(chrExt);
|
|---|
| 867 |
|
|---|
| 868 | /* copy file name into file name buffer */
|
|---|
| 869 | strcpy ( szFullPath, fdg.szFullFile );
|
|---|
| 870 | if (fdg.lReturn == DID_CANCEL)
|
|---|
| 871 | return FALSE;
|
|---|
| 872 | else
|
|---|
| 873 | return(TRUE);
|
|---|
| 874 | }
|
|---|
| 875 |
|
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 |
|
|---|
| 879 | //PSZ pszTypes[]= {"Bitmap",0};
|
|---|
| 880 |
|
|---|
| 881 | VOID SaveFile (HWND hwndClient, PSZ pszSource, FOURCC fccSourceIOProc )
|
|---|
| 882 | {
|
|---|
| 883 | FILEDLG fdg;
|
|---|
| 884 | HWND hwndDlg;
|
|---|
| 885 | INT Result;
|
|---|
| 886 | PSZ Result1;
|
|---|
| 887 | char *chrExt=NULLHANDLE;
|
|---|
| 888 |
|
|---|
| 889 | CHAR Test[STRING_LENGTH];
|
|---|
| 890 | CHAR VID[]=".VID";
|
|---|
| 891 | CHAR DIB[]=".DIB";
|
|---|
| 892 | CHAR PCX[]=".PCX";
|
|---|
| 893 | CHAR TGA[]=".TGA";
|
|---|
| 894 | CHAR TIF[]=".TIF";
|
|---|
| 895 | CHAR RDI[]=".RDI";
|
|---|
| 896 | CHAR BMP[]=".BMP";
|
|---|
| 897 | FOURCC fccTargetIOProc;
|
|---|
| 898 |
|
|---|
| 899 | chrExt=_getExtFromImageIOProc(TRUE); /* Get image extensions */
|
|---|
| 900 |
|
|---|
| 901 | memset(&fdg, 0, sizeof(FILEDLG));
|
|---|
| 902 | fdg.cbSize = sizeof(FILEDLG);
|
|---|
| 903 | fdg.fl = FDS_SAVEAS_DIALOG | FDS_CENTER;
|
|---|
| 904 | fdg.pszTitle = "The Save File Dialog";
|
|---|
| 905 | //fdg.papszITypeList=(PAPSZ)pszTypes;
|
|---|
| 906 | /* strcpy(fdg.szFullFile, "*.bmp");*/
|
|---|
| 907 | strcpy( fdg.szFullFile, chrExt);
|
|---|
| 908 |
|
|---|
| 909 | hwndDlg= WinFileDlg(HWND_DESKTOP, hwndClient, (PFILEDLG) &fdg);
|
|---|
| 910 | if (hwndDlg && (fdg.lReturn == DID_OK))
|
|---|
| 911 | {
|
|---|
| 912 | Result1 = strchr(fdg.szFullFile,'.');
|
|---|
| 913 | if(Result1 = "NULL")
|
|---|
| 914 | Result1 = "BMP";
|
|---|
| 915 | strcpy(Test,Result1);
|
|---|
| 916 |
|
|---|
| 917 | strupr(Test);
|
|---|
| 918 | if(strcmp(Test, VID) == 0 && mmioFOURCC('M','M','O','T') > 0)
|
|---|
| 919 | fccTargetIOProc = mmioFOURCC('M','M','O','T');
|
|---|
| 920 | else if(strcmp(Test, RDI) == 0 && mmioFOURCC('R','D','I','B') > 0)
|
|---|
| 921 | fccTargetIOProc = mmioFOURCC('R','D','I','B');
|
|---|
| 922 | else if(strcmp(Test, PCX) == 0 && mmioFOURCC('P','C','X','C') > 0)
|
|---|
| 923 | fccTargetIOProc = mmioFOURCC('P','C','X','C');
|
|---|
| 924 | else if(strcmp(Test, BMP) == 0 && mmioFOURCC('O','S','2','0') > 0)
|
|---|
| 925 | fccTargetIOProc = mmioFOURCC('O','S','2','0');
|
|---|
| 926 | else if(strcmp(Test, DIB) == 0 && mmioFOURCC('W','1','3','0') > 0)
|
|---|
| 927 | fccTargetIOProc = mmioFOURCC('W','1','3','0');
|
|---|
| 928 | else if(strcmp(Test, TGA) == 0 && mmioFOURCC('T','G','A','U') > 0)
|
|---|
| 929 | fccTargetIOProc = mmioFOURCC('T','G','A','U');
|
|---|
| 930 | else if(strcmp(Test, TIF) == 0 && mmioFOURCC('T','I','F','U') > 0)
|
|---|
| 931 | fccTargetIOProc = mmioFOURCC('T','I','F','U');
|
|---|
| 932 | else
|
|---|
| 933 | {
|
|---|
| 934 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 935 | HWND_DESKTOP,
|
|---|
| 936 | "Will Save As a OS2.BMP",
|
|---|
| 937 | "Save As....",
|
|---|
| 938 | (HMODULE) NULL,
|
|---|
| 939 | (ULONG) MB_OK | MB_MOVEABLE );
|
|---|
| 940 | fccTargetIOProc = mmioFOURCC('O','S','2','0');
|
|---|
| 941 | }
|
|---|
| 942 | MakeItBusy(TRUE);
|
|---|
| 943 | DoConvert(pszSource, fccSourceIOProc, fdg.szFullFile, fccTargetIOProc);
|
|---|
| 944 | MakeItBusy(FALSE);
|
|---|
| 945 | }
|
|---|
| 946 |
|
|---|
| 947 | if(chrExt)
|
|---|
| 948 | free(chrExt);
|
|---|
| 949 |
|
|---|
| 950 | }
|
|---|
| 951 |
|
|---|
| 952 | /*************************************************************************
|
|---|
| 953 | * Name : DisplayMessageBox
|
|---|
| 954 | *
|
|---|
| 955 | * Description : This procedure will display messages for the application
|
|---|
| 956 | * based upon string IDs passed in. The actual text will be
|
|---|
| 957 | * loaded from the string table in the resource.
|
|---|
| 958 | *
|
|---|
| 959 | * Parameters : usTitleID - ID of the title string
|
|---|
| 960 | * usMessageID - ID of the message string
|
|---|
| 961 | * usStyle - Style of the message box (WinMessageBox)
|
|---|
| 962 | *
|
|---|
| 963 | * Return : none.
|
|---|
| 964 | *
|
|---|
| 965 | *************************************************************************/
|
|---|
| 966 |
|
|---|
| 967 | VOID DisplayMessageBox ( HWND hwnd,
|
|---|
| 968 | USHORT usTitleID,
|
|---|
| 969 | USHORT usMessageID,
|
|---|
| 970 | USHORT usStyle)
|
|---|
| 971 | {
|
|---|
| 972 | CHAR achTitle[STRING_LENGTH];
|
|---|
| 973 | CHAR achMessage[STRING_LENGTH];
|
|---|
| 974 | USHORT usResult;
|
|---|
| 975 |
|
|---|
| 976 | /*
|
|---|
| 977 | * Get the string from the Resource defined string table and show it
|
|---|
| 978 | * in the message box.
|
|---|
| 979 | */
|
|---|
| 980 | WinLoadString(
|
|---|
| 981 | hab, /* HAB for this dialog box. */
|
|---|
| 982 | (HMODULE) NULL, /* Get the string from the .exe file. */
|
|---|
| 983 | usTitleID, /* Which string to get. */
|
|---|
| 984 | (SHORT) sizeof( achTitle), /* The size of the buffer. */
|
|---|
| 985 | achTitle ); /* The buffer to place the string. */
|
|---|
| 986 |
|
|---|
| 987 | WinLoadString(
|
|---|
| 988 | hab, /* HAB for this dialog box. */
|
|---|
| 989 | (HMODULE) NULL, /* Get the string from the .exe file. */
|
|---|
| 990 | usMessageID, /* Which string to get. */
|
|---|
| 991 | (SHORT) sizeof( achMessage), /* The size of the buffer. */
|
|---|
| 992 | achMessage ); /* The buffer to place the string. */
|
|---|
| 993 |
|
|---|
| 994 | usResult =
|
|---|
| 995 | WinMessageBox(
|
|---|
| 996 | HWND_DESKTOP, /* Parent handle of the message box. */
|
|---|
| 997 | hwnd, /* Owner handle of the message box. */
|
|---|
| 998 | achMessage, /* String to show in the message box. */
|
|---|
| 999 | achTitle, /* Title to shown in the message box. */
|
|---|
| 1000 | (HMODULE) NULL, /* Message Box Id. Not Needed. */
|
|---|
| 1001 | (ULONG) usStyle ); /* The style of the message box. */
|
|---|
| 1002 | } /* End of DisplayMessageBox */
|
|---|
| 1003 |
|
|---|
| 1004 |
|
|---|
| 1005 | VOID FourccToString( FOURCC fcc, PSZ pszString )
|
|---|
| 1006 | {
|
|---|
| 1007 | pszString[0] = (BYTE) fcc;
|
|---|
| 1008 | pszString[1] = (BYTE) (fcc >> 8);
|
|---|
| 1009 | pszString[2] = (BYTE) (fcc >> 16);
|
|---|
| 1010 | pszString[3] = (BYTE) (fcc >> 24);
|
|---|
| 1011 | pszString[4] = 0;
|
|---|
| 1012 | }
|
|---|
| 1013 |
|
|---|
| 1014 | HBITMAP LoadBitmap ( HAB hab,
|
|---|
| 1015 | HDC hdc,
|
|---|
| 1016 | HPS *hps,
|
|---|
| 1017 | PSZ pszFileName )
|
|---|
| 1018 | {
|
|---|
| 1019 | HBITMAP hbm;
|
|---|
| 1020 | MMIOINFO mmioinfo;
|
|---|
| 1021 | MMFORMATINFO mmFormatInfo;
|
|---|
| 1022 | HMMIO hmmio;
|
|---|
| 1023 | ULONG ulImageHeaderLength;
|
|---|
| 1024 | ULONG ulBytesRead;
|
|---|
| 1025 | ULONG dwNumRowBytes;
|
|---|
| 1026 | PBYTE pRowBuffer;
|
|---|
| 1027 | ULONG dwRowCount;
|
|---|
| 1028 | SIZEL ImageSize;
|
|---|
| 1029 | ULONG dwHeight, dwWidth;
|
|---|
| 1030 | SHORT wBitCount;
|
|---|
| 1031 | FOURCC fccStorageSystem;
|
|---|
| 1032 | ULONG dwPadBytes;
|
|---|
| 1033 | ULONG dwRowBits;
|
|---|
| 1034 | ULONG ulReturnCode;
|
|---|
| 1035 | ULONG dwReturnCode;
|
|---|
| 1036 | HBITMAP hbReturnCode;
|
|---|
| 1037 | LONG lReturnCode;
|
|---|
| 1038 | FOURCC fccIOProc;
|
|---|
| 1039 |
|
|---|
| 1040 | ulReturnCode = mmioIdentifyFile ( pszFileName,
|
|---|
| 1041 | 0L,
|
|---|
| 1042 | &mmFormatInfo,
|
|---|
| 1043 | &fccStorageSystem,
|
|---|
| 1044 | 0L,
|
|---|
| 1045 | 0L);
|
|---|
| 1046 |
|
|---|
| 1047 | /*
|
|---|
| 1048 | * If this file was NOT identified, then this function won't
|
|---|
| 1049 | * work, so return an error by indicating an empty bitmap.
|
|---|
| 1050 | */
|
|---|
| 1051 | if ( ulReturnCode == MMIO_ERROR )
|
|---|
| 1052 | {
|
|---|
| 1053 | return (0L);
|
|---|
| 1054 | }
|
|---|
| 1055 |
|
|---|
| 1056 | /*
|
|---|
| 1057 | * If mmioIdentifyFile did not find a custom-written IO proc which
|
|---|
| 1058 | * can understand the image file, then it will return the DOS IO Proc
|
|---|
| 1059 | * info because the image file IS a DOS file.
|
|---|
| 1060 | */
|
|---|
| 1061 | if( mmFormatInfo.fccIOProc == FOURCC_DOS )
|
|---|
| 1062 | {
|
|---|
| 1063 |
|
|---|
| 1064 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 1065 | HWND_DESKTOP,
|
|---|
| 1066 | "Image file could not be interpreted by any permanently or temporarily installed IO procedures.",
|
|---|
| 1067 | "Open Image File",
|
|---|
| 1068 | (HMODULE) NULL,
|
|---|
| 1069 | (ULONG) MB_OK | MB_MOVEABLE |
|
|---|
| 1070 | MB_ERROR );
|
|---|
| 1071 | return ( 0L );
|
|---|
| 1072 | }
|
|---|
| 1073 |
|
|---|
| 1074 | /*
|
|---|
| 1075 | * Ensure this is an IMAGE IOproc, and that it can read
|
|---|
| 1076 | * translated data
|
|---|
| 1077 | */
|
|---|
| 1078 | if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
|
|---|
| 1079 | ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
|
|---|
| 1080 | {
|
|---|
| 1081 | WinMessageBox( HWND_DESKTOP,
|
|---|
| 1082 | HWND_DESKTOP,
|
|---|
| 1083 | "No IMAGE IO Procedures exist which can translate the data in the image file specified.",
|
|---|
| 1084 | "Open Image File",
|
|---|
| 1085 | (HMODULE) NULL,
|
|---|
| 1086 | (ULONG) MB_OK | MB_MOVEABLE |
|
|---|
| 1087 | MB_ERROR );
|
|---|
| 1088 | return (0L);
|
|---|
| 1089 | }
|
|---|
| 1090 | else
|
|---|
| 1091 | {
|
|---|
| 1092 | fccIOProc = mmFormatInfo.fccIOProc;
|
|---|
| 1093 | }
|
|---|
| 1094 |
|
|---|
| 1095 | /* Clear out and initialize mminfo structure */
|
|---|
| 1096 | memset ( &mmioinfo,
|
|---|
| 1097 | 0L,
|
|---|
| 1098 | sizeof ( MMIOINFO ) );
|
|---|
| 1099 |
|
|---|
| 1100 | mmioinfo.fccIOProc = fccIOProc;
|
|---|
| 1101 | mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
|---|
| 1102 |
|
|---|
| 1103 | hmmio = mmioOpen ( (PSZ) pszFileName,
|
|---|
| 1104 | &mmioinfo,
|
|---|
| 1105 | MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
|
|---|
| 1106 |
|
|---|
| 1107 | if ( ! hmmio )
|
|---|
| 1108 | {
|
|---|
| 1109 | // If file could not be opened, return with error
|
|---|
| 1110 | return (0L);
|
|---|
| 1111 | }
|
|---|
| 1112 |
|
|---|
| 1113 | dwReturnCode = mmioQueryHeaderLength ( hmmio,
|
|---|
| 1114 | (PLONG)&ulImageHeaderLength,
|
|---|
| 1115 | 0L,
|
|---|
| 1116 | 0L);
|
|---|
| 1117 |
|
|---|
| 1118 | if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
|
|---|
| 1119 | {
|
|---|
| 1120 | /* We have a problem.....possibly incompatible versions */
|
|---|
| 1121 | ulReturnCode = mmioClose (hmmio, 0L);
|
|---|
| 1122 |
|
|---|
| 1123 | return (0L);
|
|---|
| 1124 | }
|
|---|
| 1125 |
|
|---|
| 1126 | ulReturnCode = mmioGetHeader ( hmmio,
|
|---|
| 1127 | &mmImgHdr,
|
|---|
| 1128 | (LONG) sizeof ( MMIMAGEHEADER ),
|
|---|
| 1129 | (PLONG)&ulBytesRead,
|
|---|
| 1130 | 0L,
|
|---|
| 1131 | 0L);
|
|---|
| 1132 |
|
|---|
| 1133 | if ( ulReturnCode != MMIO_SUCCESS )
|
|---|
| 1134 | {
|
|---|
| 1135 | /* Header unavailable */
|
|---|
| 1136 |
|
|---|
| 1137 | ulReturnCode = mmioClose (hmmio, 0L);
|
|---|
| 1138 |
|
|---|
| 1139 | return (0L);
|
|---|
| 1140 | }
|
|---|
| 1141 |
|
|---|
| 1142 | /*
|
|---|
| 1143 | * Determine the number of bytes required, per row.
|
|---|
| 1144 | * PLANES MUST ALWAYS BE = 1
|
|---|
| 1145 | */
|
|---|
| 1146 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
|---|
| 1147 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
|---|
| 1148 | wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
|---|
| 1149 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
|---|
| 1150 | dwNumRowBytes = dwRowBits >> 3;
|
|---|
| 1151 |
|
|---|
| 1152 | /*
|
|---|
| 1153 | * Account for odd bits used in 1bpp or 4bpp images that are
|
|---|
| 1154 | * NOT on byte boundaries.
|
|---|
| 1155 | */
|
|---|
| 1156 | if ( dwRowBits % 8 )
|
|---|
| 1157 | {
|
|---|
| 1158 | dwNumRowBytes++;
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | /*
|
|---|
| 1162 | * Ensure the row length in bytes accounts for byte padding.
|
|---|
| 1163 | * All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
|
|---|
| 1164 | * The data FROM an IOProc should always appear in this form.
|
|---|
| 1165 | */
|
|---|
| 1166 | dwPadBytes = ( dwNumRowBytes % 4 );
|
|---|
| 1167 |
|
|---|
| 1168 | if ( dwPadBytes )
|
|---|
| 1169 | {
|
|---|
| 1170 | dwNumRowBytes += 4 - dwPadBytes;
|
|---|
| 1171 | }
|
|---|
| 1172 |
|
|---|
| 1173 | /* Allocate space for ONE row of pels */
|
|---|
| 1174 | if ( DosAllocMem( (PPVOID)&pRowBuffer,
|
|---|
| 1175 | (ULONG)dwNumRowBytes,
|
|---|
| 1176 | fALLOC))
|
|---|
| 1177 | {
|
|---|
| 1178 | ulReturnCode = mmioClose (hmmio, 0L);
|
|---|
| 1179 |
|
|---|
| 1180 | return(0L);
|
|---|
| 1181 | }
|
|---|
| 1182 |
|
|---|
| 1183 | // ***************************************************
|
|---|
| 1184 | // Create a memory presentation space that includes
|
|---|
| 1185 | // the memory device context obtained above.
|
|---|
| 1186 | // ***************************************************
|
|---|
| 1187 | ImageSize.cx = dwWidth;
|
|---|
| 1188 | ImageSize.cy = dwHeight;
|
|---|
| 1189 |
|
|---|
| 1190 | *hps = GpiCreatePS ( hab,
|
|---|
| 1191 | hdc,
|
|---|
| 1192 | &ImageSize,
|
|---|
| 1193 | PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
|
|---|
| 1194 |
|
|---|
| 1195 | if ( !*hps )
|
|---|
| 1196 | {
|
|---|
| 1197 | mmioClose (hmmio, 0L);
|
|---|
| 1198 | return(0L);
|
|---|
| 1199 | }
|
|---|
| 1200 |
|
|---|
| 1201 | // ***************************************************
|
|---|
| 1202 | // Create an uninitialized bitmap. This is where we
|
|---|
| 1203 | // will put all of the bits once we read them in.
|
|---|
| 1204 | // ***************************************************
|
|---|
| 1205 | hbm = GpiCreateBitmap ( *hps,
|
|---|
| 1206 | &mmImgHdr.mmXDIBHeader.BMPInfoHeader2,
|
|---|
| 1207 | 0L,
|
|---|
| 1208 | NULL,
|
|---|
| 1209 | NULL);
|
|---|
| 1210 | if ( !hbm )
|
|---|
| 1211 | {
|
|---|
| 1212 | ulReturnCode = mmioClose (hmmio, 0L);
|
|---|
| 1213 | return(0L);
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 | // ***************************************************
|
|---|
| 1217 | // Select the bitmap into the memory device context.
|
|---|
| 1218 | // ***************************************************
|
|---|
| 1219 | hbReturnCode = GpiSetBitmap ( *hps,
|
|---|
| 1220 | hbm );
|
|---|
| 1221 |
|
|---|
| 1222 | //***************************************************************
|
|---|
| 1223 | // LOAD THE BITMAP DATA FROM THE FILE
|
|---|
| 1224 | // One line at a time, starting from the BOTTOM
|
|---|
| 1225 | //*************************************************************** */
|
|---|
| 1226 | for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ )
|
|---|
| 1227 | {
|
|---|
| 1228 | ulBytesRead = (ULONG) mmioRead ( hmmio,
|
|---|
| 1229 | pRowBuffer,
|
|---|
| 1230 | dwNumRowBytes );
|
|---|
| 1231 | if ( !ulBytesRead )
|
|---|
| 1232 | {
|
|---|
| 1233 | break;
|
|---|
| 1234 | }
|
|---|
| 1235 |
|
|---|
| 1236 | /*
|
|---|
| 1237 | * Allow context switching while previewing.. Couldn't get
|
|---|
| 1238 | * it to work. Perhaps will get to it when time is available...
|
|---|
| 1239 | */
|
|---|
| 1240 | lReturnCode = GpiSetBitmapBits ( *hps,
|
|---|
| 1241 | (LONG) dwRowCount,
|
|---|
| 1242 | (LONG) 1,
|
|---|
| 1243 | (PBYTE) pRowBuffer,
|
|---|
| 1244 | (PBITMAPINFO2) &mmImgHdr.mmXDIBHeader.BMPInfoHeader2);
|
|---|
| 1245 |
|
|---|
| 1246 | }
|
|---|
| 1247 | ulReturnCode = mmioClose (hmmio, 0L);
|
|---|
| 1248 | DosFreeMem(pRowBuffer);
|
|---|
| 1249 | return(hbm);
|
|---|
| 1250 | }
|
|---|
| 1251 |
|
|---|
| 1252 |
|
|---|
| 1253 | /*
|
|---|
| 1254 | * GetBitMap
|
|---|
| 1255 | *
|
|---|
| 1256 | * Get a bitmap for the specified file
|
|---|
| 1257 | */
|
|---|
| 1258 | HBITMAP GetBitMap ( HWND hwnd,
|
|---|
| 1259 | PSZ pszFileName)
|
|---|
| 1260 | {
|
|---|
| 1261 | HBITMAP hBmp;
|
|---|
| 1262 | BOOL bReturnCode;
|
|---|
| 1263 |
|
|---|
| 1264 | /*
|
|---|
| 1265 | * Load Bitmap, which will then be drawn during WM_PAINT processing
|
|---|
| 1266 | *
|
|---|
| 1267 | * First, we need a memory device context. We'll keep this around
|
|---|
| 1268 | * to reuse for subsequent preview operations
|
|---|
| 1269 | */
|
|---|
| 1270 | if ( !hdcMemory )
|
|---|
| 1271 | {
|
|---|
| 1272 | hdcMemory = DevOpenDC ( WinQueryAnchorBlock(hwnd),
|
|---|
| 1273 | OD_MEMORY,
|
|---|
| 1274 | "*",
|
|---|
| 1275 | 0L,
|
|---|
| 1276 | NULL,
|
|---|
| 1277 | 0);
|
|---|
| 1278 | }
|
|---|
| 1279 |
|
|---|
| 1280 | /*
|
|---|
| 1281 | * Discard previous memory presentation space if present
|
|---|
| 1282 | */
|
|---|
| 1283 | if ( hpsMemory )
|
|---|
| 1284 | {
|
|---|
| 1285 | hBmp = GpiSetBitmap ( hpsMemory,
|
|---|
| 1286 | 0);
|
|---|
| 1287 | bReturnCode = GpiDestroyPS ( hpsMemory );
|
|---|
| 1288 | hpsMemory = 0;
|
|---|
| 1289 | }
|
|---|
| 1290 |
|
|---|
| 1291 | /*
|
|---|
| 1292 | * Delete previously loaded bitmap if present
|
|---|
| 1293 | */
|
|---|
| 1294 | if ( hBmp && hBmp != HBM_ERROR )
|
|---|
| 1295 | {
|
|---|
| 1296 | bReturnCode = GpiDeleteBitmap ( hBmp );
|
|---|
| 1297 | }
|
|---|
| 1298 |
|
|---|
| 1299 | MakeItBusy ( TRUE );
|
|---|
| 1300 |
|
|---|
| 1301 | hBmp = LoadBitmap ( WinQueryAnchorBlock(hwnd),
|
|---|
| 1302 | hdcMemory,
|
|---|
| 1303 | &hpsMemory,
|
|---|
| 1304 | pszFileName );
|
|---|
| 1305 |
|
|---|
| 1306 | MakeItBusy ( FALSE );
|
|---|
| 1307 | if (!hBmp)
|
|---|
| 1308 | {
|
|---|
| 1309 | // error in loading bitmap
|
|---|
| 1310 | }
|
|---|
| 1311 |
|
|---|
| 1312 | /*
|
|---|
| 1313 | * Be sure that the image gets repainted
|
|---|
| 1314 | */
|
|---|
| 1315 | bReturnCode = WinInvalidateRect(hwnd, NULL, FALSE);
|
|---|
| 1316 |
|
|---|
| 1317 | return hBmp;
|
|---|
| 1318 | }
|
|---|
| 1319 |
|
|---|
| 1320 | /*
|
|---|
| 1321 | * DrawBitMap
|
|---|
| 1322 | *
|
|---|
| 1323 | * Draw the previously loaded bitmap in the rectangle occupied by the
|
|---|
| 1324 | * frame ID_WINDOW.
|
|---|
| 1325 | */
|
|---|
| 1326 |
|
|---|
| 1327 | VOID DrawBitMap ( HWND hwnd )
|
|---|
| 1328 | {
|
|---|
| 1329 | SWP swp;
|
|---|
| 1330 | POINTL aptl[4];
|
|---|
| 1331 | HPS hps;
|
|---|
| 1332 | SIZEL ImageSize;
|
|---|
| 1333 | BOOL bReturnCode;
|
|---|
| 1334 | ULONG ulReturnCode;
|
|---|
| 1335 | LONG lReturnCode;
|
|---|
| 1336 | ULONG ulHeight;
|
|---|
| 1337 | ULONG ulWidth;
|
|---|
| 1338 |
|
|---|
| 1339 | /*
|
|---|
| 1340 | * Validate memory presentation space before attempting to draw bitmap
|
|---|
| 1341 | */
|
|---|
| 1342 | ulReturnCode = GpiQueryPS ( hpsMemory, &ImageSize) ;
|
|---|
| 1343 | if ( ! ulReturnCode )
|
|---|
| 1344 | {
|
|---|
| 1345 | return;
|
|---|
| 1346 | }
|
|---|
| 1347 |
|
|---|
| 1348 | hps = WinBeginPaint ( hwnd,
|
|---|
| 1349 | 0,
|
|---|
| 1350 | NULL);
|
|---|
| 1351 | /*
|
|---|
| 1352 | * Get position of image frame
|
|---|
| 1353 | */
|
|---|
| 1354 | bReturnCode = WinQueryWindowPos ( hwnd, &swp);
|
|---|
| 1355 |
|
|---|
| 1356 | /* Image size */
|
|---|
| 1357 |
|
|---|
| 1358 | ulHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
|---|
| 1359 | ulWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
|---|
| 1360 |
|
|---|
| 1361 | #if 0
|
|---|
| 1362 | ulHeight = ImageSize.cy;
|
|---|
| 1363 | ulWidth = ImageSize.cx;
|
|---|
| 1364 | /* Calculate draw position and size. Aspect ratio should be preserved. */
|
|---|
| 1365 | #endif
|
|---|
| 1366 |
|
|---|
| 1367 | if(ulWidth <=swp.cx && ulHeight <= swp.cy)
|
|---|
| 1368 | {
|
|---|
| 1369 | aptl[0].x=(swp.cx-ulWidth)/2;
|
|---|
| 1370 | aptl[1].x=aptl[0].x+ulWidth;
|
|---|
| 1371 |
|
|---|
| 1372 | aptl[0].y=(swp.cy-ulHeight)/2;
|
|---|
| 1373 | aptl[1].y=aptl[0].y+ulHeight;
|
|---|
| 1374 | }
|
|---|
| 1375 | else {
|
|---|
| 1376 | float fWidth, fHeight, fRes;
|
|---|
| 1377 |
|
|---|
| 1378 | fWidth=(float)swp.cx/(float)ulWidth;
|
|---|
| 1379 | fHeight=(float)swp.cy/(float)ulHeight;
|
|---|
| 1380 | fRes=( fWidth>fHeight ? fHeight : fWidth);
|
|---|
| 1381 |
|
|---|
| 1382 |
|
|---|
| 1383 | aptl[0].x=(swp.cx-ulWidth*fRes)/2;
|
|---|
| 1384 | aptl[1].x=aptl[0].x+ulWidth*fRes;
|
|---|
| 1385 |
|
|---|
| 1386 | aptl[0].y=(swp.cy-ulHeight*fRes)/2;
|
|---|
| 1387 | aptl[1].y=aptl[0].y+ulHeight*fRes;
|
|---|
| 1388 |
|
|---|
| 1389 | #if 0
|
|---|
| 1390 | aptl[0].x = 0; // target lower left
|
|---|
| 1391 | aptl[0].y = 0;
|
|---|
| 1392 |
|
|---|
| 1393 | aptl[1].x = swp.cx; // target upper right
|
|---|
| 1394 | aptl[1].y = swp.cy;
|
|---|
| 1395 | #endif
|
|---|
| 1396 | }
|
|---|
| 1397 |
|
|---|
| 1398 | aptl[2].x = 0; // source lower left
|
|---|
| 1399 | aptl[2].y = 0;
|
|---|
| 1400 |
|
|---|
| 1401 | aptl[3].x = ulWidth; // source upper right
|
|---|
| 1402 | aptl[3].y = ulHeight;
|
|---|
| 1403 |
|
|---|
| 1404 | /*
|
|---|
| 1405 | * Call GpiBitBlt and supply 4 aptl structures. This tells
|
|---|
| 1406 | * it to stretch or compress the bitmap depending on what is
|
|---|
| 1407 | * in the aptl structures. See above lines for their current
|
|---|
| 1408 | * settings.
|
|---|
| 1409 | */
|
|---|
| 1410 | bReturnCode = GpiSetColor (hps, GpiQueryColor (hpsMemory));
|
|---|
| 1411 | bReturnCode = GpiSetBackColor (hps, GpiQueryBackColor (hpsMemory));
|
|---|
| 1412 |
|
|---|
| 1413 | lReturnCode = GpiBitBlt (hps, hpsMemory, 4L, aptl, ROP_SRCCOPY, BBO_IGNORE);
|
|---|
| 1414 |
|
|---|
| 1415 | bReturnCode = WinEndPaint (hps);
|
|---|
| 1416 | }
|
|---|
| 1417 |
|
|---|
| 1418 |
|
|---|
| 1419 | /*************************************************************************
|
|---|
| 1420 | * Name : InitializeHelp
|
|---|
| 1421 | *
|
|---|
| 1422 | * Description : This procedure will set up the initial values in the
|
|---|
| 1423 | * global help structure. This help structure will then
|
|---|
| 1424 | * be passed on to the Help Manager when the Help Instance
|
|---|
| 1425 | * is created. The handle to the Help Instance will be
|
|---|
| 1426 | * kept for later use.
|
|---|
| 1427 | *
|
|---|
| 1428 | * Concepts : None.
|
|---|
| 1429 | *
|
|---|
| 1430 | * MME API's : None.
|
|---|
| 1431 | *
|
|---|
| 1432 | * Parameters : None.
|
|---|
| 1433 | *
|
|---|
| 1434 | * Return : TRUE - error encountered
|
|---|
| 1435 | * FALSE - no errors encountered - help instance created!
|
|---|
| 1436 | *
|
|---|
| 1437 | *************************************************************************/
|
|---|
| 1438 | VOID InitializeHelp( HWND hwndFrame)
|
|---|
| 1439 | {
|
|---|
| 1440 | HELPINIT hini;
|
|---|
| 1441 | fHelpEnabled = FALSE;
|
|---|
| 1442 | /* if we return because of an error, Help will be disabled */
|
|---|
| 1443 |
|
|---|
| 1444 | /* initialize help init structure */
|
|---|
| 1445 | hini.cb = sizeof(HELPINIT);
|
|---|
| 1446 | hini.ulReturnCode = 0;
|
|---|
| 1447 | hini.pszTutorialName = (PSZ)NULL; /* if tutorial added, add name here */
|
|---|
| 1448 | hini.phtHelpTable = (PHELPTABLE)MAKELONG(MMBROWSER_HELP_TABLE, 0xFFFF);
|
|---|
| 1449 | hini.hmodHelpTableModule = 0L;
|
|---|
| 1450 | hini.hmodAccelActionBarModule = 0L;
|
|---|
| 1451 | hini.idAccelTable = 0L;
|
|---|
| 1452 | hini.idActionBar = 0L;
|
|---|
| 1453 | hini.pszHelpWindowTitle = "MMBrowser Help";
|
|---|
| 1454 | hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
|
|---|
| 1455 | hini.pszHelpLibraryName = "MMBROWSE.HLP";
|
|---|
| 1456 |
|
|---|
| 1457 | /* creating help instance */
|
|---|
| 1458 |
|
|---|
| 1459 | hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
|
|---|
| 1460 |
|
|---|
| 1461 | if(!hwndHelpInstance || hini.ulReturnCode)
|
|---|
| 1462 | {
|
|---|
| 1463 | return;
|
|---|
| 1464 | }
|
|---|
| 1465 |
|
|---|
| 1466 | /* associate help instance with main frame */
|
|---|
| 1467 |
|
|---|
| 1468 | if(!WinAssociateHelpInstance(hwndHelpInstance, hwndFrame))
|
|---|
| 1469 | {
|
|---|
| 1470 | return;
|
|---|
| 1471 |
|
|---|
| 1472 | }
|
|---|
| 1473 |
|
|---|
| 1474 | fHelpEnabled = TRUE;
|
|---|
| 1475 | }
|
|---|
| 1476 |
|
|---|
| 1477 | /****************************************************************
|
|---|
| 1478 | * Dialog procedure for the About dialog box
|
|---|
| 1479 | *--------------------------------------------------------------
|
|---|
| 1480 | *
|
|---|
| 1481 | * Name: AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1482 | *
|
|---|
| 1483 | * Purpose: Handles all the messages associated with the About Box
|
|---|
| 1484 | *
|
|---|
| 1485 | * Usage: Called for each message sent to the About Box dialog box.
|
|---|
| 1486 | *
|
|---|
| 1487 | * Method: The about box only has a button control so this routine
|
|---|
| 1488 | * only processes WM_COMMAND messages. Any WM_COMMAND
|
|---|
| 1489 | * posted must have come from the Ok button so we dismiss
|
|---|
| 1490 | * the dialog upon receiving it.
|
|---|
| 1491 | *
|
|---|
| 1492 | * Returns: Dependent upon message sent
|
|---|
| 1493 | *
|
|---|
| 1494 | ****************************************************************/
|
|---|
| 1495 | MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 1496 | {
|
|---|
| 1497 | MRESULT sRC;
|
|---|
| 1498 |
|
|---|
| 1499 | switch(msg)
|
|---|
| 1500 | {
|
|---|
| 1501 | case WM_INITDLG:
|
|---|
| 1502 | // FixSysMenu(hwnd);
|
|---|
| 1503 | return (MRESULT)0L;
|
|---|
| 1504 |
|
|---|
| 1505 | case WM_COMMAND:
|
|---|
| 1506 | WinDismissDlg(hwnd, TRUE);
|
|---|
| 1507 | return (MRESULT)0L;
|
|---|
| 1508 |
|
|---|
| 1509 | default:
|
|---|
| 1510 | sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 1511 | return sRC;
|
|---|
| 1512 | }
|
|---|
| 1513 | return (MRESULT)0L;
|
|---|
| 1514 | }
|
|---|
| 1515 |
|
|---|
| 1516 | /****************************************************************
|
|---|
| 1517 | * FixSysMenu procedure
|
|---|
| 1518 | *--------------------------------------------------------------
|
|---|
| 1519 | *
|
|---|
| 1520 | * Name: FixSysMenu(HWND hwndDlg)
|
|---|
| 1521 | *
|
|---|
| 1522 | * Purpose: This routine removes the Restore, Size, Minimize, and
|
|---|
| 1523 | * Maximize options from the system menu of a dialog.
|
|---|
| 1524 | *
|
|---|
| 1525 | * Usage
|
|---|
| 1526 | *
|
|---|
| 1527 | * Method: Called during the WM_INITDLG of a dialog procedure.
|
|---|
| 1528 | *
|
|---|
| 1529 | * Returns: VOID
|
|---|
| 1530 | *
|
|---|
| 1531 | ****************************************************************/
|
|---|
| 1532 | VOID FixSysMenu(HWND hwndDlg)
|
|---|
| 1533 | {
|
|---|
| 1534 | HWND hwndMenu; /* Handle to system menu */
|
|---|
| 1535 |
|
|---|
| 1536 | hwndMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
|
|---|
| 1537 |
|
|---|
| 1538 | WinSendMsg(hwndMenu, /* Delete Restore from the system menu */
|
|---|
| 1539 | MM_DELETEITEM,
|
|---|
| 1540 | MPFROM2SHORT(SC_RESTORE, TRUE),
|
|---|
| 1541 | MPFROMP(NULL));
|
|---|
| 1542 |
|
|---|
| 1543 | WinSendMsg(hwndMenu, /* Delete Size from the system menu */
|
|---|
| 1544 | MM_DELETEITEM,
|
|---|
| 1545 | MPFROM2SHORT(SC_SIZE, TRUE),
|
|---|
| 1546 | MPFROMP(NULL));
|
|---|
| 1547 |
|
|---|
| 1548 | WinSendMsg(hwndMenu, /* Delete Minimize from the system menu */
|
|---|
| 1549 | MM_DELETEITEM,
|
|---|
| 1550 | MPFROM2SHORT(SC_MINIMIZE, TRUE),
|
|---|
| 1551 | MPFROMP(NULL));
|
|---|
| 1552 |
|
|---|
| 1553 | WinSendMsg(hwndMenu, /* Delete Maximize from the system menu */
|
|---|
| 1554 | MM_DELETEITEM,
|
|---|
| 1555 | MPFROM2SHORT(SC_MAXIMIZE, TRUE),
|
|---|
| 1556 | MPFROMP(NULL));
|
|---|
| 1557 | return;
|
|---|
| 1558 | }
|
|---|
| 1559 |
|
|---|
| 1560 | //*******************************************************************
|
|---|
| 1561 | // Function : DoConvert
|
|---|
| 1562 | //
|
|---|
| 1563 | //
|
|---|
| 1564 | // Description :
|
|---|
| 1565 | // This function provides a simple method of converting an
|
|---|
| 1566 | // image from one format to another, so long as both are
|
|---|
| 1567 | // supported by OS/2 MME MMIO IOProcs. It uses MMIO
|
|---|
| 1568 | // functions to transparently open, read and write file headers,
|
|---|
| 1569 | // read and write image data, and close the files.
|
|---|
| 1570 | //
|
|---|
| 1571 | // This function will also signal the progress of the conversion
|
|---|
| 1572 | // so that this progress can illustrated to a user.
|
|---|
| 1573 | //
|
|---|
| 1574 | // Parameters (all input, unchanged by function):
|
|---|
| 1575 | // Source file name
|
|---|
| 1576 | // Source file IOProc handler
|
|---|
| 1577 | // Target file name
|
|---|
| 1578 | // Target file IOProc handler
|
|---|
| 1579 | //
|
|---|
| 1580 | // Return Code:
|
|---|
| 1581 | // 0 if successful, or
|
|---|
| 1582 | // ERR_CANCELLED
|
|---|
| 1583 | // ERR_SOURCEOPEN
|
|---|
| 1584 | // ERR_TARGETOPEN
|
|---|
| 1585 | // ERR_SOURCEHEADER
|
|---|
| 1586 | // ERR_TARGETHEADER
|
|---|
| 1587 | // ERR_SOURCEWRITE
|
|---|
| 1588 | // ERR_TARGETWRITE
|
|---|
| 1589 | // ERR_SOURCECLOSE
|
|---|
| 1590 | // ERR_TARGETCLOSE
|
|---|
| 1591 | // ERR_MEMORY
|
|---|
| 1592 | //
|
|---|
| 1593 | //********************************************************************
|
|---|
| 1594 | BOOL DoConvert(
|
|---|
| 1595 | PSZ pszSource, // Source file name
|
|---|
| 1596 | FOURCC fccSourceIOProc,
|
|---|
| 1597 | PSZ pszTarget,
|
|---|
| 1598 | FOURCC fccTargetIOProc) //
|
|---|
| 1599 | {
|
|---|
| 1600 | MMIOINFO mmioinfoSource;
|
|---|
| 1601 | MMIOINFO mmioinfoTarget;
|
|---|
| 1602 | HMMIO hmmioSource;
|
|---|
| 1603 | HMMIO hmmioTarget;
|
|---|
| 1604 | ULONG ulImageHeaderLength;
|
|---|
| 1605 | MMIMAGEHEADER mmImgHdr;
|
|---|
| 1606 | ULONG ulBytesRead;
|
|---|
| 1607 | ULONG dwNumRowBytes;
|
|---|
| 1608 | PBYTE pRowBuffer;
|
|---|
| 1609 | ULONG dwRowCount;
|
|---|
| 1610 | ULONG dwWidth;
|
|---|
| 1611 | ULONG dwHeight;
|
|---|
| 1612 | ULONG dwPadBytes;
|
|---|
| 1613 | ULONG dwRowBits;
|
|---|
| 1614 | LONG rc;
|
|---|
| 1615 | LONG rcSrcQueryCount = 0;
|
|---|
| 1616 | LONG rcTrgQueryCount = 0;
|
|---|
| 1617 | LONG rcTrgSetImage = 0;
|
|---|
| 1618 | ULONG iIndex, iCount, iCount2;
|
|---|
| 1619 |
|
|---|
| 1620 |
|
|---|
| 1621 |
|
|---|
| 1622 | /*******************************/
|
|---|
| 1623 | /* Set up/open the SOURCE file */
|
|---|
| 1624 | /*******************************/
|
|---|
| 1625 | memset (&mmioinfoSource, 0L, sizeof (MMIOINFO));
|
|---|
| 1626 | mmioinfoSource.fccIOProc = fccSourceIOProc;
|
|---|
| 1627 | mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
|---|
| 1628 | memset (&mmioinfoTarget, 0L, sizeof (MMIOINFO));
|
|---|
| 1629 | mmioinfoTarget.fccIOProc = fccTargetIOProc;
|
|---|
| 1630 | mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
|
|---|
| 1631 |
|
|---|
| 1632 | hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource,
|
|---|
| 1633 | MMIO_READ | MMIO_DENYWRITE
|
|---|
| 1634 | | MMIO_NOIDENTIFY);
|
|---|
| 1635 |
|
|---|
| 1636 | if (!hmmioSource)
|
|---|
| 1637 | return (ERR_SOURCEOPEN);
|
|---|
| 1638 |
|
|---|
| 1639 | /*******************************/
|
|---|
| 1640 | /* Set up/open the TARGET file */
|
|---|
| 1641 | /*******************************/
|
|---|
| 1642 |
|
|---|
| 1643 |
|
|---|
| 1644 | hmmioTarget = mmioOpen ((PSZ)pszTarget,
|
|---|
| 1645 | &mmioinfoTarget,
|
|---|
| 1646 | MMIO_CREATE | MMIO_WRITE |
|
|---|
| 1647 | MMIO_DENYWRITE | MMIO_NOIDENTIFY);
|
|---|
| 1648 |
|
|---|
| 1649 | if (!hmmioTarget)
|
|---|
| 1650 | {
|
|---|
| 1651 | mmioClose (hmmioSource, 0L);
|
|---|
| 1652 | return (ERR_TARGETOPEN);
|
|---|
| 1653 | }
|
|---|
| 1654 |
|
|---|
| 1655 | // find out if source has multiple image support
|
|---|
| 1656 | rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0);
|
|---|
| 1657 | if (rcSrcQueryCount) iCount = 1;
|
|---|
| 1658 |
|
|---|
| 1659 | // find out if the target has multiple image support
|
|---|
| 1660 | rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0);
|
|---|
| 1661 |
|
|---|
| 1662 | for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */
|
|---|
| 1663 |
|
|---|
| 1664 | if (!rcSrcQueryCount && !rcTrgQueryCount) { /* if Both support images */
|
|---|
| 1665 |
|
|---|
| 1666 | /* Determine if the target can write arrays, and if not */
|
|---|
| 1667 | /* then write the the default image from the source */
|
|---|
| 1668 |
|
|---|
| 1669 | if (rcTrgSetImage && iIndex > 0) break; /* Target Can't Write array */
|
|---|
| 1670 |
|
|---|
| 1671 | /* Now, determine if the target can write arrays */
|
|---|
| 1672 | rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
|
|---|
| 1673 |
|
|---|
| 1674 | if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
|
|---|
| 1675 |
|
|---|
| 1676 | } else if (!rcSrcQueryCount) { /* Source does but target doesn't */
|
|---|
| 1677 | /* Use the default image from source to copy to target */
|
|---|
| 1678 | /* so do set the index of the first, let it default */
|
|---|
| 1679 | /* get the base photo cd image (2 of 5) */
|
|---|
| 1680 | if (iIndex > 0) break;
|
|---|
| 1681 | } else if (!rcTrgQueryCount) { /* Target does but source doesn't */
|
|---|
| 1682 | /* Use the only image to do a default write to target */
|
|---|
| 1683 | } else {
|
|---|
| 1684 | /* neither do: just write one image from here to there */
|
|---|
| 1685 | }
|
|---|
| 1686 |
|
|---|
| 1687 | /****************************/
|
|---|
| 1688 | /* Obtain the SOURCE HEADER */
|
|---|
| 1689 | /****************************/
|
|---|
| 1690 | mmioQueryHeaderLength (hmmioSource, (PLONG)&ulImageHeaderLength, 0L, 0L);
|
|---|
| 1691 | if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
|
|---|
| 1692 | /* We have a problem.....possibly incompatible versions */
|
|---|
| 1693 | {
|
|---|
| 1694 | mmioClose (hmmioSource, 0L);
|
|---|
| 1695 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1696 | return (ERR_SOURCEHEADER);
|
|---|
| 1697 | }
|
|---|
| 1698 |
|
|---|
| 1699 | rc = (LONG)mmioGetHeader (hmmioSource, &mmImgHdr,
|
|---|
| 1700 | (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
|
|---|
| 1701 | 0L, 0L);
|
|---|
| 1702 |
|
|---|
| 1703 | if (rc != MMIO_SUCCESS)
|
|---|
| 1704 | /* Header unavailable */
|
|---|
| 1705 | {
|
|---|
| 1706 | mmioClose (hmmioSource, 0L);
|
|---|
| 1707 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1708 | return (ERR_SOURCEHEADER);
|
|---|
| 1709 | }
|
|---|
| 1710 |
|
|---|
| 1711 |
|
|---|
| 1712 | /*************************/
|
|---|
| 1713 | /* Set the TARGET HEADER */
|
|---|
| 1714 | /*************************/
|
|---|
| 1715 | mmioQueryHeaderLength (hmmioTarget, (PLONG)&ulImageHeaderLength, 0L, 0L);
|
|---|
| 1716 | if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
|
|---|
| 1717 | {
|
|---|
| 1718 | /* We have a problem.....possibly incompatible versions */
|
|---|
| 1719 | mmioClose (hmmioSource, 0L);
|
|---|
| 1720 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1721 | return (ERR_TARGETHEADER);
|
|---|
| 1722 | }
|
|---|
| 1723 |
|
|---|
| 1724 | /* Use the SAME data as came from the SOURCE FILE. It must be
|
|---|
| 1725 | compatible with the OS/2 bitmaps, etc. */
|
|---|
| 1726 | rc = (LONG)mmioSetHeader (hmmioTarget, &mmImgHdr,
|
|---|
| 1727 | (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
|
|---|
| 1728 | 0L, 0L);
|
|---|
| 1729 |
|
|---|
| 1730 | if (rc != MMIO_SUCCESS)
|
|---|
| 1731 | /* Header unavailable */
|
|---|
| 1732 | {
|
|---|
| 1733 | mmioClose (hmmioSource, 0L);
|
|---|
| 1734 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1735 | return (ERR_TARGETHEADER);
|
|---|
| 1736 | }
|
|---|
| 1737 |
|
|---|
| 1738 |
|
|---|
| 1739 | /* Determine the number of bytes required, per row */
|
|---|
| 1740 | /* PLANES MUST ALWAYS BE = 1 */
|
|---|
| 1741 | dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
|
|---|
| 1742 | dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
|
|---|
| 1743 | dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
|
|---|
| 1744 | dwNumRowBytes = dwRowBits >> 3;
|
|---|
| 1745 |
|
|---|
| 1746 | /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */
|
|---|
| 1747 | if (dwRowBits % 8)
|
|---|
| 1748 | dwNumRowBytes++;
|
|---|
| 1749 |
|
|---|
| 1750 | /* Ensure the row length in bytes accounts for byte padding. All bitmap data rows
|
|---|
| 1751 | must are aligned on LONG/4-BYTE boundaries. The data FROM an IOProc
|
|---|
| 1752 | should always appear in this form. */
|
|---|
| 1753 | dwPadBytes = (dwNumRowBytes % 4);
|
|---|
| 1754 | if (dwPadBytes)
|
|---|
| 1755 | dwNumRowBytes += 4 - dwPadBytes;
|
|---|
| 1756 |
|
|---|
| 1757 | /* Allocate space for one row */
|
|---|
| 1758 | if (DosAllocMem((PVOID)&pRowBuffer, (ULONG)dwNumRowBytes, fALLOC))
|
|---|
| 1759 | {
|
|---|
| 1760 | mmioClose (hmmioSource, 0L);
|
|---|
| 1761 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1762 | return(ERR_MEMORY);
|
|---|
| 1763 | }
|
|---|
| 1764 |
|
|---|
| 1765 | for (dwRowCount = 0;
|
|---|
| 1766 | dwRowCount < dwHeight;
|
|---|
| 1767 | dwRowCount++)
|
|---|
| 1768 | {
|
|---|
| 1769 | ulBytesRead = (ULONG)mmioRead (hmmioSource, pRowBuffer, dwNumRowBytes);
|
|---|
| 1770 |
|
|---|
| 1771 | if (ulBytesRead)
|
|---|
| 1772 | mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
|
|---|
| 1773 | else
|
|---|
| 1774 | break;
|
|---|
| 1775 |
|
|---|
| 1776 | }
|
|---|
| 1777 | }
|
|---|
| 1778 |
|
|---|
| 1779 | mmioClose (hmmioSource, 0L);
|
|---|
| 1780 | mmioClose (hmmioTarget, 0L);
|
|---|
| 1781 |
|
|---|
| 1782 | DosFreeMem(pRowBuffer);
|
|---|
| 1783 | return(0);
|
|---|
| 1784 | }
|
|---|
| 1785 |
|
|---|