| 1 | /*
|
|---|
| 2 | * mmfind.c (C) Chris Wohlgemuth 2004-2005
|
|---|
| 3 | *
|
|---|
| 4 | */
|
|---|
| 5 | /*
|
|---|
| 6 | * This program is free software; you can redistribute it and/or modify
|
|---|
| 7 | * it under the terms of the GNU General Public License as published by
|
|---|
| 8 | * the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | * any later version.
|
|---|
| 10 | *
|
|---|
| 11 | * This program is distributed in the hope that it will be useful,
|
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 14 | * GNU General Public License for more details.
|
|---|
| 15 | *
|
|---|
| 16 | * You should have received a copy of the GNU General Public License
|
|---|
| 17 | * along with this program; see the file COPYING. If not, write to
|
|---|
| 18 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 19 | */
|
|---|
| 20 | /*
|
|---|
| 21 | * If you need another license for your project/product (commercial,
|
|---|
| 22 | * noncommercial, whatever) contact me at
|
|---|
| 23 | *
|
|---|
| 24 | * http://www.os2world.com/cdwriting
|
|---|
| 25 | * http://www.geocities.com/SiliconValley/Sector/5785/
|
|---|
| 26 | *
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #define INCL_DOS
|
|---|
| 30 | #define INCL_DOSFILEMGR
|
|---|
| 31 | #define INCL_DOSERRORS
|
|---|
| 32 | #define INCL_WIN
|
|---|
| 33 | #define INCL_WINWORKPLACE
|
|---|
| 34 | #define INCL_OS2MM
|
|---|
| 35 | #define INCL_MMIOOS2
|
|---|
| 36 | #define INCL_MCIOS2
|
|---|
| 37 | #define INCL_GPI
|
|---|
| 38 | #define INCL_PM
|
|---|
| 39 | #define INCL_REXXSAA
|
|---|
| 40 |
|
|---|
| 41 | /* OS/2 and compiler includes */
|
|---|
| 42 | #include <os2.h>
|
|---|
| 43 | #include <sys\types.h>
|
|---|
| 44 | #include <sys\stat.h>
|
|---|
| 45 | #include <stdio.h>
|
|---|
| 46 | #include <string.h>
|
|---|
| 47 | #include <stdlib.h>
|
|---|
| 48 | #include "os2me.h"
|
|---|
| 49 | /* CW toolkit includes */
|
|---|
| 50 | #include "sys_funcs.h"
|
|---|
| 51 | #include "message_funcs.h"
|
|---|
| 52 | #include "window_funcs.h"
|
|---|
| 53 | #include "img_funcs.h"
|
|---|
| 54 | #include "ini_funcs.h"
|
|---|
| 55 | /* Program includes */
|
|---|
| 56 | #include "common.h"
|
|---|
| 57 | #include "mmres.h" /* Ressource IDs */
|
|---|
| 58 | #include "mmprogs_defaults.h"
|
|---|
| 59 | //#define DEBUG
|
|---|
| 60 | #include "mmfind.h" /* mmfind specific defines */
|
|---|
| 61 |
|
|---|
| 62 | char logName[]="mmfind.log"; /* To keep some (unused) helpers in helper.c happy */
|
|---|
| 63 |
|
|---|
| 64 | char chrIniFile[CCHMAXPATH];
|
|---|
| 65 | char chrInstallDir[CCHMAXPATH];
|
|---|
| 66 |
|
|---|
| 67 | char chrLastAudioDir[CCHMAXPATH];
|
|---|
| 68 | char chrLastVideoDir[CCHMAXPATH];
|
|---|
| 69 | char chrLastImageDir[CCHMAXPATH];
|
|---|
| 70 |
|
|---|
| 71 | /***** For previewing audio tracks *****/
|
|---|
| 72 | char chrSourceName[CCHMAXPATH]; /* The audio file to be played */
|
|---|
| 73 | BOOL bIsMidi=FALSE; /* No MIDI support atm */
|
|---|
| 74 | BOOL bIsPlaying=FALSE; /* TRUE if currently playing */
|
|---|
| 75 | BOOL bPaused=FALSE;
|
|---|
| 76 | ULONG ulPos;
|
|---|
| 77 | ULONG ulTotalLength;
|
|---|
| 78 | HWND hwndPlayer; /* HWND of the player object window used for async coommunication */
|
|---|
| 79 |
|
|---|
| 80 | /***************************************/
|
|---|
| 81 |
|
|---|
| 82 | #define NUMPARAMS 1
|
|---|
| 83 | /*
|
|---|
| 84 | argv[0]: progname
|
|---|
| 85 | */
|
|---|
| 86 | int numArgs;
|
|---|
| 87 | char* params[NUMPARAMS];
|
|---|
| 88 |
|
|---|
| 89 | HMODULE RESSOURCEHANDLE=0;
|
|---|
| 90 |
|
|---|
| 91 | char chrMediaFileTypes[NUMMEDIATYPES][100];
|
|---|
| 92 |
|
|---|
| 93 | char chrMediaFileExt[NUMMEDIATYPES][EXT_STRING_LENGTH]= {"*.AIF;*.AU;*.FLA;*.FLAC;*.IFF;*.MID;*.MP3;*.OGG;*.SND;*.VOC;*.WAV;*._AU",
|
|---|
| 94 | /* The image extensions are queried using the imageext.rx and imageadd.rx scripts */
|
|---|
| 95 | "*.BMP;*.DIB;*.GIF;*.JPG;*.PCX;*.PNG;*.PCD;*.TIF;*.TGA;*.VID;*._IM",
|
|---|
| 96 | "*.AVI;*.MPG;*.FLI;*.FLC;*.MOV;*.QT;*.VBS"};
|
|---|
| 97 | /* Additional audio extensions to be queried during runtime */
|
|---|
| 98 | char chrAdditionalExt[200];
|
|---|
| 99 | /* This holds the template used when building the audio information text */
|
|---|
| 100 | char audioText[255];
|
|---|
| 101 |
|
|---|
| 102 | int iMediaType=MT_AUDIO;
|
|---|
| 103 |
|
|---|
| 104 | /* BMP stuff for preview */
|
|---|
| 105 | BITMAPINFOHEADER2 bmpInfoHeader2;
|
|---|
| 106 | HBITMAP hBitmap;
|
|---|
| 107 |
|
|---|
| 108 | /* HBITMAP for the play control buttons */
|
|---|
| 109 | HBITMAP hbmPlay;
|
|---|
| 110 | HBITMAP hbmStop;
|
|---|
| 111 |
|
|---|
| 112 | FILEDLG fd = { 0 };
|
|---|
| 113 |
|
|---|
| 114 | static void _loadButtonBmps()
|
|---|
| 115 | {
|
|---|
| 116 | HPS hps;
|
|---|
| 117 | HMODULE hResource;
|
|---|
| 118 |
|
|---|
| 119 | hResource=NULLHANDLE;
|
|---|
| 120 | hps=WinGetPS(HWND_DESKTOP);
|
|---|
| 121 |
|
|---|
| 122 | /* Play */
|
|---|
| 123 | hbmPlay=GpiLoadBitmap(hps, hResource, IDBMP_PLAY, 0, 0);
|
|---|
| 124 |
|
|---|
| 125 | /* Stop */
|
|---|
| 126 | hbmStop=GpiLoadBitmap(hps, hResource, IDBMP_STOP, 0, 0);
|
|---|
| 127 |
|
|---|
| 128 | WinReleasePS(hps);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | static void changeButtons(HWND hwnd)
|
|---|
| 132 | {
|
|---|
| 133 | HWND hwndTemp;
|
|---|
| 134 | BTNCDATA btCtrl;
|
|---|
| 135 | WNDPARAMS wndParams;
|
|---|
| 136 | ULONG ulStyle;
|
|---|
| 137 |
|
|---|
| 138 | if(hbmPlay) {
|
|---|
| 139 | hwndTemp=WinWindowFromID(hwnd, IDPB_MMFINDPLAY);
|
|---|
| 140 |
|
|---|
| 141 | /* Change Style to bitmap */
|
|---|
| 142 | ulStyle=WinQueryWindowULong(hwndTemp,QWL_STYLE);
|
|---|
| 143 | ulStyle|=(BS_BITMAP);
|
|---|
| 144 | ulStyle&=~BS_TEXT;
|
|---|
| 145 |
|
|---|
| 146 | if(WinSetWindowULong(hwndTemp, QWL_STYLE, ulStyle)) {
|
|---|
| 147 | memset(&btCtrl, 0, sizeof(btCtrl));
|
|---|
| 148 | btCtrl.cb=sizeof(btCtrl);
|
|---|
| 149 | btCtrl.hImage=hbmPlay;
|
|---|
| 150 | memset(&wndParams, 0, sizeof(wndParams));
|
|---|
| 151 | wndParams.fsStatus=WPM_CTLDATA;
|
|---|
| 152 | wndParams.cbCtlData=btCtrl.cb;
|
|---|
| 153 | wndParams.pCtlData=&btCtrl;
|
|---|
| 154 | WinSendMsg(hwndTemp,WM_SETWINDOWPARAMS,
|
|---|
| 155 | MPFROMP(&wndParams),0);
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | if(hbmStop) {
|
|---|
| 160 | hwndTemp=WinWindowFromID(hwnd, IDPB_MMFINDSTOP);
|
|---|
| 161 | /* Change Style to bitmap */
|
|---|
| 162 | ulStyle=WinQueryWindowULong(hwndTemp,QWL_STYLE);
|
|---|
| 163 | ulStyle|=(BS_BITMAP);
|
|---|
| 164 | ulStyle&=~BS_TEXT;
|
|---|
| 165 |
|
|---|
| 166 | if(WinSetWindowULong(hwndTemp, QWL_STYLE, ulStyle)) {
|
|---|
| 167 | memset(&btCtrl, 0, sizeof(btCtrl));
|
|---|
| 168 | btCtrl.cb=sizeof(btCtrl);
|
|---|
| 169 | btCtrl.hImage=hbmStop;
|
|---|
| 170 | memset(&wndParams, 0, sizeof(wndParams));
|
|---|
| 171 | wndParams.fsStatus=WPM_CTLDATA;
|
|---|
| 172 | wndParams.cbCtlData=btCtrl.cb;
|
|---|
| 173 | wndParams.pCtlData=&btCtrl;
|
|---|
| 174 | WinSendMsg(hwndTemp,WM_SETWINDOWPARAMS,
|
|---|
| 175 | MPFROMP(&wndParams),0);
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | static char* translateChars(char * chrString, char chrFrom, char chrTo)
|
|---|
| 181 | {
|
|---|
| 182 | char *chr=chrString;
|
|---|
| 183 |
|
|---|
| 184 | if(chrTo == '\0' || chrFrom=='\0'|| chrString==NULLHANDLE)
|
|---|
| 185 | return NULLHANDLE;
|
|---|
| 186 |
|
|---|
| 187 | while(*chr)
|
|---|
| 188 | {
|
|---|
| 189 | if(*chr==chrFrom)
|
|---|
| 190 | *chr=chrTo;
|
|---|
| 191 |
|
|---|
| 192 | chr++;
|
|---|
| 193 | }
|
|---|
| 194 | return chrString;
|
|---|
| 195 | }
|
|---|
| 196 |
|
|---|
| 197 | static void loadStringsFromResourceDLL(HMODULE hResMod)
|
|---|
| 198 | {
|
|---|
| 199 | if(!MsgGetMessage(audioText, IDSTR_AUDIOINFOTEXT, sizeof(audioText), hResMod,HWND_DESKTOP))
|
|---|
| 200 | strcpy(audioText, TEXT_INFOTEXT);
|
|---|
| 201 | if(!MsgGetMessage(chrMediaFileTypes[MT_AUDIO], IDSTR_TYPEAUDIO,
|
|---|
| 202 | sizeof(chrMediaFileTypes[MT_AUDIO]), hResMod, HWND_DESKTOP))
|
|---|
| 203 | strcpy(chrMediaFileTypes[MT_AUDIO], TEXT_TYPEAUDIO);
|
|---|
| 204 | if(!MsgGetMessage(chrMediaFileTypes[MT_IMAGE], IDSTR_TYPEIMAGE,
|
|---|
| 205 | sizeof(chrMediaFileTypes[MT_IMAGE]), hResMod, HWND_DESKTOP))
|
|---|
| 206 | strcpy(chrMediaFileTypes[MT_AUDIO], TEXT_TYPEIMAGE);
|
|---|
| 207 | if(!MsgGetMessage(chrMediaFileTypes[MT_VIDEO], IDSTR_TYPEVIDEO,
|
|---|
| 208 | sizeof(chrMediaFileTypes[MT_VIDEO]), hResMod, HWND_DESKTOP))
|
|---|
| 209 | strcpy(chrMediaFileTypes[MT_VIDEO], TEXT_TYPEVIDEO);
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | static void showVideoControls(HWND hwnd, BOOL bShow)
|
|---|
| 213 | {
|
|---|
| 214 | /* Preview area */
|
|---|
| 215 | WinShowWindow(WinWindowFromID(hwnd, IDST_NOPREVIEWAVAILABLE), bShow);
|
|---|
| 216 | /* Group box */
|
|---|
| 217 | WinShowWindow(WinWindowFromID(hwnd, IDGB_PREVIEW), bShow);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 | static void enableAudioPlayControls(HWND hwnd, BOOL bEnable)
|
|---|
| 222 | {
|
|---|
| 223 | WinEnableWindow(WinWindowFromID(hwnd, IDPB_MMFINDPAUSE), bEnable);
|
|---|
| 224 | WinEnableWindow(WinWindowFromID(hwnd, IDPB_MMFINDPLAY), bEnable);
|
|---|
| 225 | WinEnableWindow(WinWindowFromID(hwnd, IDPB_MMFINDSTOP), bEnable);
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | void showAudioControls(HWND hwnd, BOOL bShow)
|
|---|
| 229 | {
|
|---|
| 230 | /* Preview area */
|
|---|
| 231 | WinShowWindow(WinWindowFromID(hwnd, IDST_AUDIOINFO), bShow);
|
|---|
| 232 | /* Group box */
|
|---|
| 233 | WinShowWindow(WinWindowFromID(hwnd, IDGB_AUDIOINFO), bShow);
|
|---|
| 234 | /* Playcontrols */
|
|---|
| 235 | WinShowWindow(WinWindowFromID(hwnd, IDPB_MMFINDPLAY), bShow);
|
|---|
| 236 | WinShowWindow(WinWindowFromID(hwnd, IDPB_MMFINDSTOP), bShow);
|
|---|
| 237 | WinShowWindow(WinWindowFromID(hwnd, IDPB_MMFINDPAUSE), bShow);
|
|---|
| 238 | if(bShow) {
|
|---|
| 239 | WinSetWindowToTop(WinWindowFromID(hwnd, IDPB_MMFINDPAUSE));
|
|---|
| 240 | WinSetWindowToTop(WinWindowFromID(hwnd, IDPB_MMFINDPLAY));
|
|---|
| 241 | WinSetWindowToTop(WinWindowFromID(hwnd, IDPB_MMFINDSTOP));
|
|---|
| 242 | enableAudioPlayControls(hwnd, FALSE);
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | BOOL pauseAudioFile(HWND hwndNotify)
|
|---|
| 247 | {
|
|---|
| 248 | #if 0
|
|---|
| 249 | char chrCommand[50];
|
|---|
| 250 | char retMsg[100];
|
|---|
| 251 | ULONG rc;
|
|---|
| 252 |
|
|---|
| 253 | iWavePriv=ulPid;
|
|---|
| 254 |
|
|---|
| 255 | if(bPaused) {
|
|---|
| 256 | sprintf(chrCommand,"RESUME wave%d wait", hwndNotify);
|
|---|
| 257 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 258 | bPaused=FALSE;
|
|---|
| 259 | showPlayTimeDisplay( hwndFrame, TRUE);
|
|---|
| 260 | }
|
|---|
| 261 | else {
|
|---|
| 262 | sprintf(chrCommand,"PAUSE wave%d wait", iWavePriv);
|
|---|
| 263 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 264 | bPaused=TRUE;
|
|---|
| 265 | }
|
|---|
| 266 | #endif
|
|---|
| 267 | return TRUE;
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | BOOL stopAudioFile(HWND hwndNotify)
|
|---|
| 271 | {
|
|---|
| 272 | char chrCommand[50];
|
|---|
| 273 | char retMsg[100];
|
|---|
| 274 | ULONG rc;
|
|---|
| 275 |
|
|---|
| 276 | if(bIsPlaying) {
|
|---|
| 277 | sprintf(chrCommand,"stop wave%ld wait", hwndNotify);
|
|---|
| 278 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 279 |
|
|---|
| 280 | sprintf(chrCommand,"close wave%ld wait", hwndNotify);
|
|---|
| 281 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 282 |
|
|---|
| 283 | #if 0
|
|---|
| 284 | _resetDisplay(hwndFrame);
|
|---|
| 285 | showPlayTimeDisplay( hwndFrame, TRUE);
|
|---|
| 286 | WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY);
|
|---|
| 287 | #endif
|
|---|
| 288 | bIsPlaying=FALSE;
|
|---|
| 289 | bPaused=FALSE;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | return TRUE;
|
|---|
| 293 | }
|
|---|
| 294 |
|
|---|
| 295 | ULONG playAudioFile(HWND hwndFrame)
|
|---|
| 296 | {
|
|---|
| 297 | char chrCommand[CCHMAXPATH*2];
|
|---|
| 298 | char chrDevice[30];
|
|---|
| 299 | char retMsg[20];
|
|---|
| 300 | ULONG rc;
|
|---|
| 301 | int iTime2;
|
|---|
| 302 | HWND hwndNotify;
|
|---|
| 303 |
|
|---|
| 304 | hwndNotify=hwndFrame;//WinWindowFromID(hwndTop, IDDLG_TOPMIDDLE);
|
|---|
| 305 |
|
|---|
| 306 | if(bPaused)
|
|---|
| 307 | {
|
|---|
| 308 | pauseAudioFile(hwndFrame);
|
|---|
| 309 | return 1;
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | ulPos=0;
|
|---|
| 313 |
|
|---|
| 314 | stopAudioFile(hwndFrame);
|
|---|
| 315 |
|
|---|
| 316 | if(bIsMidi)
|
|---|
| 317 | strncpy(chrDevice,"SEQUENCER", sizeof(chrDevice));
|
|---|
| 318 | else
|
|---|
| 319 | strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice));
|
|---|
| 320 |
|
|---|
| 321 | /* Start audio file */
|
|---|
| 322 | sprintf(chrCommand,"open \"%s\" type %s alias wave%ld SHAREABLE wait", chrSourceName, chrDevice, hwndNotify);
|
|---|
| 323 |
|
|---|
| 324 |
|
|---|
| 325 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), hwndNotify, 0);
|
|---|
| 326 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS)
|
|---|
| 327 | return 0;
|
|---|
| 328 |
|
|---|
| 329 | /* Set time format */
|
|---|
| 330 | sprintf(chrCommand,"SET wave%ld TIME FORMAT MILLISECONDS wait", hwndNotify);
|
|---|
| 331 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 332 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
|---|
| 333 | sprintf(chrCommand,"close wave%ld wait", hwndNotify);
|
|---|
| 334 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 335 | return 0;
|
|---|
| 336 | }
|
|---|
| 337 |
|
|---|
| 338 | #if 0
|
|---|
| 339 | sprintf(chrCommand,"SETPOSITIONADVISE wave%d ON EVERY 1000 notify", iWavePriv);
|
|---|
| 340 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg),hwndNotify, 0);
|
|---|
| 341 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
|---|
| 342 | sprintf(chrCommand,"close wave%d wait",iWavePriv);
|
|---|
| 343 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 344 | return 0;
|
|---|
| 345 | }
|
|---|
| 346 | #endif
|
|---|
| 347 |
|
|---|
| 348 | /* Get wave length in ms */
|
|---|
| 349 | iTime2=0;
|
|---|
| 350 | sprintf(chrCommand,"STATUS wave%ld LENGTH WAIT", hwndNotify);
|
|---|
| 351 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 352 | if((rc & 0x0000ffff)==MCIERR_SUCCESS) {
|
|---|
| 353 | iTime2=atoi(retMsg);
|
|---|
| 354 | sprintf(chrCommand,"%d:%02d %d:%02d -%d:%02d",iTime2/1000/60,(iTime2/1000)%60,
|
|---|
| 355 | 0, 0,
|
|---|
| 356 | iTime2/1000/60,(iTime2/1000)%60);
|
|---|
| 357 | }
|
|---|
| 358 | ulTotalLength=iTime2;
|
|---|
| 359 |
|
|---|
| 360 | #if 0
|
|---|
| 361 | /* Set volume */
|
|---|
| 362 | sprintf(chrCommand,"SET wave%ld AUDIO VOLUME %ld wait", hwndFrame, ulVolume);
|
|---|
| 363 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 364 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
|---|
| 365 | sprintf(chrCommand,"close wave%d",iWavePriv);
|
|---|
| 366 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 367 | return 0;
|
|---|
| 368 | }
|
|---|
| 369 | #endif
|
|---|
| 370 |
|
|---|
| 371 | sprintf(chrCommand,"play wave%ld FROM 0", hwndNotify);
|
|---|
| 372 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 373 | if((rc & 0x0000ffff)!=MCIERR_SUCCESS) {
|
|---|
| 374 | sprintf(chrCommand,"close wave%ld", hwndNotify);
|
|---|
| 375 | rc = mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
|---|
| 376 | return 0;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | #if 0
|
|---|
| 380 | WinStartTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY, PLAYTIMER_DELAY);
|
|---|
| 381 | #endif
|
|---|
| 382 |
|
|---|
| 383 | bIsPlaying=TRUE;
|
|---|
| 384 |
|
|---|
| 385 | return 1;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | static MRESULT EXPENTRY playObjectProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 389 | {
|
|---|
| 390 | switch (msg)
|
|---|
| 391 | {
|
|---|
| 392 | case WM_APPTERMINATENOTIFY:
|
|---|
| 393 | {
|
|---|
| 394 |
|
|---|
| 395 | HWND hwndFrame=HWNDFROMMP(mp2);
|
|---|
| 396 | switch(LONGFROMMP(mp1))
|
|---|
| 397 | {
|
|---|
| 398 | case PLAY_FILE:
|
|---|
| 399 | playAudioFile(hwndFrame);
|
|---|
| 400 | break;
|
|---|
| 401 | case STOP_TRACK:
|
|---|
| 402 | stopAudioFile(hwndFrame);
|
|---|
| 403 | break;
|
|---|
| 404 | case PAUSE_TRACK:
|
|---|
| 405 | pauseAudioFile(hwndFrame);
|
|---|
| 406 | break;
|
|---|
| 407 | default:
|
|---|
| 408 | break;
|
|---|
| 409 | }
|
|---|
| 410 | return (MRESULT)0;
|
|---|
| 411 | }
|
|---|
| 412 | case WM_CLOSE:
|
|---|
| 413 |
|
|---|
| 414 | break;
|
|---|
| 415 | default:
|
|---|
| 416 | break;
|
|---|
| 417 | }
|
|---|
| 418 | return WinDefWindowProc( hwnd, msg, mp1, mp2);
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | /* Every folder has one running play thread to handle play commands */
|
|---|
| 422 | void _Optlink playThreadFunc (void *arg)
|
|---|
| 423 | {
|
|---|
| 424 | HAB hab;
|
|---|
| 425 | HMQ hmq;
|
|---|
| 426 | QMSG qmsg;
|
|---|
| 427 | HWND hwndNotify=(HWND)arg;
|
|---|
| 428 |
|
|---|
| 429 | hab=WinInitialize(0);
|
|---|
| 430 | if(hab) {
|
|---|
| 431 | hmq=WinCreateMsgQueue(hab,0);
|
|---|
| 432 | if(hmq) {
|
|---|
| 433 | HWND hwndPlayObject;
|
|---|
| 434 | hwndPlayObject=WinCreateWindow(HWND_OBJECT,WC_STATIC,"MMAudioPlayObj",
|
|---|
| 435 | 0,0,0,0,0,NULLHANDLE,HWND_BOTTOM,13343,NULL,NULL);
|
|---|
| 436 | if(hwndPlayObject) {
|
|---|
| 437 | WinSubclassWindow(hwndPlayObject,&playObjectProc);
|
|---|
| 438 | /* Window created. */
|
|---|
| 439 | WinPostMsg(hwndNotify, WM_APPTERMINATENOTIFY, MPFROMSHORT(MMAUDIO_PLAYER_CREATED),
|
|---|
| 440 | MPFROMHWND(hwndPlayObject));
|
|---|
| 441 | while(WinGetMsg(hab,&qmsg,(HWND)NULL,0,0))
|
|---|
| 442 | WinDispatchMsg(hab,&qmsg);
|
|---|
| 443 |
|
|---|
| 444 | WinDestroyWindow(hwndPlayObject);
|
|---|
| 445 | }
|
|---|
| 446 | WinDestroyMsgQueue(hmq);
|
|---|
| 447 | }
|
|---|
| 448 | WinTerminate(hab);
|
|---|
| 449 | }
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 | void MMAudioPlayFile(HWND hwndPlayer, HWND hwndNotify, char* chrFile)
|
|---|
| 454 | {
|
|---|
| 455 | WinPostMsg(hwndPlayer, WM_APPTERMINATENOTIFY, MPFROMSHORT(PLAY_FILE), MPFROMHWND(hwndNotify));
|
|---|
| 456 | }
|
|---|
| 457 |
|
|---|
| 458 | void MMAudioStop(HWND hwndPlayer, HWND hwndNotify)
|
|---|
| 459 | {
|
|---|
| 460 | WinPostMsg(hwndPlayer, WM_APPTERMINATENOTIFY, MPFROMSHORT(STOP_TRACK), MPFROMHWND(hwndNotify));
|
|---|
| 461 | }
|
|---|
| 462 |
|
|---|
| 463 | void MMAudioPause(HWND hwndPlayer, HWND hwndNotify)
|
|---|
| 464 | {
|
|---|
| 465 | WinPostMsg(hwndPlayer, WM_APPTERMINATENOTIFY, MPFROMSHORT(PAUSE_TRACK), MPFROMHWND(hwndNotify));
|
|---|
| 466 | }
|
|---|
| 467 |
|
|---|
| 468 | BOOL MMAudioOpenPlayer(HWND hwndNotify)
|
|---|
| 469 | {
|
|---|
| 470 | if(-1==_beginthread(playThreadFunc,NULL,8192*16, (void*)hwndNotify))
|
|---|
| 471 | return FALSE; /* Error occured */
|
|---|
| 472 |
|
|---|
| 473 | return TRUE;
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | void MMAudioClosePlayer(HWND hwndPlayer)
|
|---|
| 477 | {
|
|---|
| 478 | WinSendMsg(hwndPlayer, WM_QUIT, 0, 0);
|
|---|
| 479 | return;
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | static ULONG mmIdentifyFile(char* chrFile)
|
|---|
| 483 | {
|
|---|
| 484 | MMIOINFO mmioInfo={0};
|
|---|
| 485 | MMFORMATINFO mmFormatInfo={0};
|
|---|
| 486 | FOURCC fourCC;
|
|---|
| 487 |
|
|---|
| 488 | if(MMIO_SUCCESS!=mmioIdentifyFile(chrFile, &mmioInfo, &mmFormatInfo, &fourCC, 0,0))
|
|---|
| 489 | {
|
|---|
| 490 | return MT_UNKNOWN;
|
|---|
| 491 | }
|
|---|
| 492 |
|
|---|
| 493 | switch(mmFormatInfo.ulMediaType)
|
|---|
| 494 | {
|
|---|
| 495 | case MMIO_MEDIATYPE_MIDI: /* Midi */
|
|---|
| 496 | case MMIO_MEDIATYPE_AUDIO: /* Any other audio file */
|
|---|
| 497 | return MT_AUDIO;
|
|---|
| 498 | case MMIO_MEDIATYPE_IMAGE:
|
|---|
| 499 | return MT_IMAGE;
|
|---|
| 500 | case MMIO_MEDIATYPE_DIGITALVIDEO:
|
|---|
| 501 | case MMIO_MEDIATYPE_MOVIE:
|
|---|
| 502 | return MT_VIDEO;
|
|---|
| 503 | default:
|
|---|
| 504 | return MT_UNKNOWN;
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | return 0;
|
|---|
| 508 | }
|
|---|
| 509 |
|
|---|
| 510 | static PSZ queryExeDir(const char *chrEXE)
|
|---|
| 511 | {
|
|---|
| 512 | if(chrInstallDir[0]==0)
|
|---|
| 513 | {
|
|---|
| 514 | char * chr;
|
|---|
| 515 | strlcpy(chrInstallDir, chrEXE, sizeof(chrInstallDir));
|
|---|
| 516 | if((chr=strrchr(chrInstallDir, '\\'))!=NULLHANDLE)
|
|---|
| 517 | *chr='\0';
|
|---|
| 518 | }
|
|---|
| 519 | return chrInstallDir;
|
|---|
| 520 | }
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 | MRESULT findFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 524 | {
|
|---|
| 525 |
|
|---|
| 526 | switch(msg)
|
|---|
| 527 | {
|
|---|
| 528 | case WM_INITDLG:
|
|---|
| 529 | {
|
|---|
| 530 | int a;
|
|---|
| 531 | SWCNTRL swctl;
|
|---|
| 532 | PID pid;
|
|---|
| 533 |
|
|---|
| 534 | /* Set dialog font */
|
|---|
| 535 | if(SysQueryOSRelease()>=40) {
|
|---|
| 536 | WinSetPresParam(hwnd,
|
|---|
| 537 | PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
|
|---|
| 538 | DEFAULT_DIALOG_FONT );
|
|---|
| 539 | }
|
|---|
| 540 | /* Fill combo box with media types (audio, image, video) */
|
|---|
| 541 | for(a=0;a<NUMMEDIATYPES;a++)
|
|---|
| 542 | WinSendMsg(WinWindowFromID(hwnd, IDCB_TYPEOFFILE), LM_INSERTITEM, MRFROMSHORT(LIT_SORTASCENDING),
|
|---|
| 543 | MPFROMP(chrMediaFileTypes[a]));
|
|---|
| 544 | WinSetWindowText(WinWindowFromID(hwnd, IDCB_TYPEOFFILE), chrMediaFileTypes[0]);
|
|---|
| 545 |
|
|---|
| 546 | /* Subclass preview area */
|
|---|
| 547 | WinSubclassWindow(WinWindowFromID(hwnd, IDSR_IMGPREVIEW), bmpPreviewProc);
|
|---|
| 548 |
|
|---|
| 549 | /* Add switch entry */
|
|---|
| 550 | memset(&swctl,0,sizeof(swctl));
|
|---|
| 551 | WinQueryWindowProcess(hwnd,&pid,NULL);
|
|---|
| 552 | swctl.hwnd=hwnd;
|
|---|
| 553 | swctl.uchVisibility=SWL_VISIBLE;
|
|---|
| 554 | swctl.idProcess=pid;
|
|---|
| 555 | swctl.bProgType=PROG_DEFAULT;
|
|---|
| 556 | swctl.fbJump=SWL_JUMPABLE;
|
|---|
| 557 | WinAddSwitchEntry(&swctl);
|
|---|
| 558 |
|
|---|
| 559 | /* Add bitmap to play control buttons */
|
|---|
| 560 | changeButtons(hwnd);
|
|---|
| 561 |
|
|---|
| 562 | /* Start an audio player thread */
|
|---|
| 563 | MMAudioOpenPlayer(hwnd);
|
|---|
| 564 | break;
|
|---|
| 565 | }
|
|---|
| 566 | case WM_APPTERMINATENOTIFY:
|
|---|
| 567 | {
|
|---|
| 568 | /* Posted from player object window */
|
|---|
| 569 | switch(SHORT1FROMMP(mp1))
|
|---|
| 570 | {
|
|---|
| 571 | case MMAUDIO_PLAYER_CREATED:
|
|---|
| 572 | /* Player object window */
|
|---|
| 573 | hwndPlayer=HWNDFROMMP(mp2);
|
|---|
| 574 | break;
|
|---|
| 575 | default:
|
|---|
| 576 | break;
|
|---|
| 577 | }
|
|---|
| 578 | return MRFALSE;
|
|---|
| 579 | }
|
|---|
| 580 | case WM_CONTROL:
|
|---|
| 581 | {
|
|---|
| 582 | switch(SHORT1FROMMP(mp1))
|
|---|
| 583 | {
|
|---|
| 584 | case IDCB_TYPEOFFILE:
|
|---|
| 585 | {
|
|---|
| 586 | if(SHORT2FROMMP(mp1)==CBN_EFCHANGE) {
|
|---|
| 587 | char chrText[100];
|
|---|
| 588 | int a;
|
|---|
| 589 | WinQueryWindowText(HWNDFROMMP(mp2), sizeof(chrText), chrText);
|
|---|
| 590 | /* Find Index */
|
|---|
| 591 | for(a=0; a<NUMMEDIATYPES;a++) {
|
|---|
| 592 | if(!stricmp(chrMediaFileTypes[a], chrText))
|
|---|
| 593 | break;
|
|---|
| 594 | }
|
|---|
| 595 | /* Error!??!*/
|
|---|
| 596 | switch(a)
|
|---|
| 597 | {
|
|---|
| 598 | case 0: /* Audio */
|
|---|
| 599 | {
|
|---|
| 600 | showVideoControls(hwnd, FALSE);
|
|---|
| 601 | showImageControls(hwnd, FALSE);
|
|---|
| 602 | showAudioControls(hwnd, TRUE);
|
|---|
| 603 | iMediaType=MT_AUDIO;
|
|---|
| 604 | break;
|
|---|
| 605 | }
|
|---|
| 606 | case 1: /* Image */
|
|---|
| 607 | showAudioControls(hwnd, FALSE);
|
|---|
| 608 | showVideoControls(hwnd, FALSE);
|
|---|
| 609 | showImageControls(hwnd, TRUE);
|
|---|
| 610 | iMediaType=MT_IMAGE;
|
|---|
| 611 | break;
|
|---|
| 612 | case 2:
|
|---|
| 613 | showAudioControls(hwnd, FALSE);
|
|---|
| 614 | showImageControls(hwnd, FALSE);
|
|---|
| 615 | showVideoControls(hwnd, TRUE);
|
|---|
| 616 | iMediaType=MT_VIDEO;
|
|---|
| 617 | break;
|
|---|
| 618 | default:
|
|---|
| 619 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 620 | }
|
|---|
| 621 | WinSetWindowText(WinWindowFromID(hwnd, 258), chrMediaFileExt[a]);
|
|---|
| 622 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, 258));
|
|---|
| 623 | WinSendMsg(WinWindowFromID(hwnd, 258), WM_CHAR,
|
|---|
| 624 | MPFROM2SHORT(KC_VIRTUALKEY , 0), MPFROM2SHORT(0, VK_NEWLINE));
|
|---|
| 625 | }
|
|---|
| 626 | break;
|
|---|
| 627 | }
|
|---|
| 628 | case 258:
|
|---|
| 629 | {
|
|---|
| 630 | if(SHORT2FROMMP(mp1)==EN_CHANGE)
|
|---|
| 631 | WinStartTimer(WinQueryAnchorBlock(HWND_DESKTOP), hwnd, TIMERID_SELECTION, 100);
|
|---|
| 632 | break;
|
|---|
| 633 | }
|
|---|
| 634 | default:
|
|---|
| 635 | break;
|
|---|
| 636 | }
|
|---|
| 637 | break;
|
|---|
| 638 | }
|
|---|
| 639 | case WM_TIMER:
|
|---|
| 640 | switch(SHORT1FROMMP(mp1))
|
|---|
| 641 | {
|
|---|
| 642 | case TIMERID_SELECTION:
|
|---|
| 643 | {
|
|---|
| 644 | char chrName[CCHMAXPATH];
|
|---|
| 645 | char chrFullName[CCHMAXPATH*2];
|
|---|
| 646 |
|
|---|
| 647 | WinStopTimer(WinQueryAnchorBlock(HWND_DESKTOP), hwnd, TIMERID_SELECTION);
|
|---|
| 648 | WinQueryWindowText(WinWindowFromID(hwnd, 258), sizeof(chrName), chrName);
|
|---|
| 649 | strcpy(chrFullName, fd.szFullFile);
|
|---|
| 650 | switch(iMediaType)
|
|---|
| 651 | {
|
|---|
| 652 | case MT_AUDIO:
|
|---|
| 653 | strlcpy(chrLastAudioDir, fd.szFullFile, sizeof(chrLastAudioDir));
|
|---|
| 654 | break;
|
|---|
| 655 | case MT_IMAGE:
|
|---|
| 656 | strlcpy(chrLastImageDir, fd.szFullFile, sizeof(chrLastImageDir));
|
|---|
| 657 | break;
|
|---|
| 658 | case MT_VIDEO:
|
|---|
| 659 | strlcpy(chrLastImageDir, fd.szFullFile, sizeof(chrLastImageDir));
|
|---|
| 660 | break;
|
|---|
| 661 | default:
|
|---|
| 662 | break;
|
|---|
| 663 | }
|
|---|
| 664 | strcat(chrFullName, chrName);
|
|---|
| 665 | strlcpy(chrSourceName, chrFullName, sizeof(chrSourceName));
|
|---|
| 666 | switch(iMediaType)
|
|---|
| 667 | {
|
|---|
| 668 | case MT_AUDIO:
|
|---|
| 669 | {
|
|---|
| 670 | char text[500];
|
|---|
| 671 | MMIOINFO mmio;
|
|---|
| 672 | HMMIO hmmio;
|
|---|
| 673 | MMAUDIOHEADER mmAudioHeader={0};
|
|---|
| 674 | LONG lBytesRead=0;
|
|---|
| 675 | ULONG rc;
|
|---|
| 676 | ULONG ulPlaySecs;
|
|---|
| 677 |
|
|---|
| 678 | MMAudioStop(hwndPlayer, hwnd);
|
|---|
| 679 |
|
|---|
| 680 | memset(&mmio,0, sizeof(mmio));
|
|---|
| 681 | mmio.ulFlags=MMIO_READ;
|
|---|
| 682 | mmio.ulTranslate=MMIO_TRANSLATEHEADER;
|
|---|
| 683 |
|
|---|
| 684 | hmmio = mmioOpen(chrFullName, &mmio, MMIO_READ);
|
|---|
| 685 | if(!hmmio)
|
|---|
| 686 | break;
|
|---|
| 687 |
|
|---|
| 688 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
|---|
| 689 | rc = mmioGetHeader(hmmio, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
|---|
| 690 | &lBytesRead, 0, 0);
|
|---|
| 691 |
|
|---|
| 692 | mmioClose(hmmio, 0);
|
|---|
| 693 | if(rc!=MMIO_SUCCESS) {
|
|---|
| 694 | WinSetWindowText(WinWindowFromID(hwnd, IDST_AUDIOINFO), "");
|
|---|
| 695 | enableAudioPlayControls(hwnd, FALSE);
|
|---|
| 696 | break;
|
|---|
| 697 | }
|
|---|
| 698 |
|
|---|
| 699 | ulPlaySecs=mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInMS/1000;
|
|---|
| 700 | sprintf(text, audioText, ulPlaySecs/60, ulPlaySecs%60,
|
|---|
| 701 | mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec,
|
|---|
| 702 | mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample,
|
|---|
| 703 | mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels);
|
|---|
| 704 | WinSetWindowText(WinWindowFromID(hwnd, IDST_AUDIOINFO), text);
|
|---|
| 705 | enableAudioPlayControls(hwnd, TRUE);
|
|---|
| 706 | break;
|
|---|
| 707 | }
|
|---|
| 708 | case MT_IMAGE:
|
|---|
| 709 | if(hBitmap) {
|
|---|
| 710 | HBITMAP hBitmapTemp;
|
|---|
| 711 | // hBitmapTemp=loadBitmap (chrFullName, &bmpInfoHeader2);
|
|---|
| 712 | hBitmapTemp=ImgLoadImageFileAndHeader(chrFullName, &bmpInfoHeader2);
|
|---|
| 713 | GpiDeleteBitmap(hBitmap);
|
|---|
| 714 | hBitmap=hBitmapTemp;
|
|---|
| 715 | }
|
|---|
| 716 | else
|
|---|
| 717 | hBitmap=ImgLoadImageFileAndHeader(chrFullName, &bmpInfoHeader2);
|
|---|
| 718 | // hBitmap=loadBitmap (chrFullName, &bmpInfoHeader2);
|
|---|
| 719 | /* Force redraw of preview area */
|
|---|
| 720 | WinInvalidateRect(WinWindowFromID(hwnd, IDSR_IMGPREVIEW), NULLHANDLE, FALSE);
|
|---|
| 721 | break;
|
|---|
| 722 | case MT_VIDEO:
|
|---|
| 723 | break;
|
|---|
| 724 | default:
|
|---|
| 725 | break;
|
|---|
| 726 | }
|
|---|
| 727 | return MRFALSE;
|
|---|
| 728 | }
|
|---|
| 729 | default:
|
|---|
| 730 | break;
|
|---|
| 731 | }
|
|---|
| 732 | case WM_COMMAND:
|
|---|
| 733 | switch(SHORT1FROMMP(mp1))
|
|---|
| 734 | {
|
|---|
| 735 | case IDPB_MMFINDPLAY:
|
|---|
| 736 | {
|
|---|
| 737 | MMAudioPlayFile(hwndPlayer, hwnd, NULLHANDLE);
|
|---|
| 738 | return MRFALSE;
|
|---|
| 739 | }
|
|---|
| 740 | case IDPB_MMFINDSTOP:
|
|---|
| 741 | {
|
|---|
| 742 | MMAudioStop(hwndPlayer, hwnd);
|
|---|
| 743 | return MRFALSE;
|
|---|
| 744 | }
|
|---|
| 745 | case IDPB_MMFINDPAUSE:
|
|---|
| 746 | {
|
|---|
| 747 | MMAudioPause(hwndPlayer, hwnd);
|
|---|
| 748 | return MRFALSE;
|
|---|
| 749 | }
|
|---|
| 750 | case IDPB_NEWFILE: /* New */
|
|---|
| 751 | {
|
|---|
| 752 | HOBJECT hObject;
|
|---|
| 753 |
|
|---|
| 754 | MMAudioStop(hwndPlayer, hwnd);
|
|---|
| 755 | MMAudioClosePlayer(hwndPlayer);
|
|---|
| 756 |
|
|---|
| 757 | /* Open the MM templates folder */
|
|---|
| 758 | if((hObject=WinQueryObject("<MMPM2_MMTEMPLATEFOLDER>"))!=NULLHANDLE) {
|
|---|
| 759 | WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
|---|
| 760 | WinDismissDlg(hwnd, DID_CANCEL);
|
|---|
| 761 | }
|
|---|
| 762 | else
|
|---|
| 763 | MsgShowMessageBox(hwnd, IDSTR_NOMMTEMPLATEFLDRTITLE, IDSTR_NOMMTEMPLATEFLDR,
|
|---|
| 764 | RESSOURCEHANDLE, MB_MOVEABLE|MB_OK);
|
|---|
| 765 | return MRFALSE;
|
|---|
| 766 | }
|
|---|
| 767 | default:
|
|---|
| 768 | // MMAudioStop(hwndPlayer, hwnd);
|
|---|
| 769 | stopAudioFile(hwnd);
|
|---|
| 770 | MMAudioClosePlayer(hwndPlayer);
|
|---|
| 771 | // DosSleep(1000);
|
|---|
| 772 | break;
|
|---|
| 773 | }
|
|---|
| 774 | default:
|
|---|
| 775 | break;
|
|---|
| 776 | }
|
|---|
| 777 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 778 | }
|
|---|
| 779 |
|
|---|
| 780 | BOOL getStringFromRexxScript(PSZ pszBinDir, PSZ rexxFile, char* chrResult, ULONG ulSize)
|
|---|
| 781 | {
|
|---|
| 782 |
|
|---|
| 783 | RXSTRING arg[1]; /* argument string for REXX */
|
|---|
| 784 | RXSTRING rexxretval; /* return value from REXX */
|
|---|
| 785 | APIRET rc; /* return code from REXX */
|
|---|
| 786 | SHORT rexxrc = 0; /* return code from function */
|
|---|
| 787 | char theScript[CCHMAXPATH];
|
|---|
| 788 | /* By setting the strlength of the output RXSTRING to zero, we */
|
|---|
| 789 | /* force the interpreter to allocate memory and return it to us. */
|
|---|
| 790 | /* We could provide a buffer for the interpreter to use instead. */
|
|---|
| 791 | rexxretval.strlength = 0L; /* initialize return to empty*/
|
|---|
| 792 |
|
|---|
| 793 | sprintf(theScript, "%s\\%s", pszBinDir, rexxFile);
|
|---|
| 794 |
|
|---|
| 795 | /* Here we call the interpreter. We don't really need to use */
|
|---|
| 796 | /* all the casts in this call; they just help illustrate */
|
|---|
| 797 | /* the data types used. */
|
|---|
| 798 | rc=RexxStart((LONG) 0, /* number of arguments */
|
|---|
| 799 | (PRXSTRING) &arg, /* array of arguments */
|
|---|
| 800 | (PSZ) theScript, /* name of REXX file */
|
|---|
| 801 | (PRXSTRING) 0, /* No INSTORE used */
|
|---|
| 802 | (PSZ) "CWRXX", /* Command env. name */
|
|---|
| 803 | (LONG) RXSUBROUTINE, /* Code for how invoked */
|
|---|
| 804 | (PRXSYSEXIT) 0, /* No EXITs on this call */
|
|---|
| 805 | (PSHORT) &rexxrc, /* Rexx program output */
|
|---|
| 806 | (PRXSTRING) &rexxretval ); /* Rexx program output */
|
|---|
| 807 | #if 0
|
|---|
| 808 | if(rc) {
|
|---|
| 809 | sprintf(text,"Error in the Rexx skript %s\n\n Get more information with 'help REX%04d'.\n",
|
|---|
| 810 | tPt->rexxSkript, rc*-1);
|
|---|
| 811 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE|MB_ERROR);
|
|---|
| 812 | }
|
|---|
| 813 | #endif
|
|---|
| 814 | if(!rc) {
|
|---|
| 815 | if(ulSize>rexxretval.strlength) {
|
|---|
| 816 | strncpy(chrResult, rexxretval.strptr, rexxretval.strlength);
|
|---|
| 817 | chrResult[rexxretval.strlength]=0;
|
|---|
| 818 | }
|
|---|
| 819 | else
|
|---|
| 820 | strncpy(chrResult, rexxretval.strptr, ulSize);
|
|---|
| 821 | chrResult[ulSize-1]=0;
|
|---|
| 822 | }
|
|---|
| 823 | if(rexxretval.strptr)
|
|---|
| 824 | DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */
|
|---|
| 825 | if(!rc)
|
|---|
| 826 | return TRUE;
|
|---|
| 827 | else
|
|---|
| 828 | return FALSE;
|
|---|
| 829 | }
|
|---|
| 830 | /*
|
|---|
| 831 | This function checks the installed image IO procs and adds extensions which are not yet handled
|
|---|
| 832 | to the list of known extensions.
|
|---|
| 833 | */
|
|---|
| 834 | static BOOL getMissingExtFromImageIOProc(char *chrMMImageKnownExt, ULONG ulSize)
|
|---|
| 835 | {
|
|---|
| 836 | MMFORMATINFO mmFormatInfo;
|
|---|
| 837 | PMMFORMATINFO pmmFormatInfoArray;
|
|---|
| 838 | void * memPtr;
|
|---|
| 839 | ULONG ulReturnCode;
|
|---|
| 840 | LONG lFormatsRead;
|
|---|
| 841 | LONG index;
|
|---|
| 842 | LONG lNumIOProcs;
|
|---|
| 843 |
|
|---|
| 844 | memset( &mmFormatInfo,
|
|---|
| 845 | '\0',
|
|---|
| 846 | sizeof(MMFORMATINFO) );
|
|---|
| 847 |
|
|---|
| 848 | mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
|
|---|
| 849 | mmFormatInfo.ulFlags|=MMIO_CANREADTRANSLATED;/* Read !!!*/
|
|---|
| 850 | ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
|
|---|
| 851 | &lNumIOProcs,
|
|---|
| 852 | 0,
|
|---|
| 853 | 0 );
|
|---|
| 854 |
|
|---|
| 855 | if( ulReturnCode != MMIO_SUCCESS )
|
|---|
| 856 | {
|
|---|
| 857 | /*
|
|---|
| 858 | * Error - mmioQueryFormatCount failed.
|
|---|
| 859 | */
|
|---|
| 860 | return FALSE;
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | /*
|
|---|
| 864 | * Allocate enough memory for n number of FormatInfo blocks
|
|---|
| 865 | */
|
|---|
| 866 | pmmFormatInfoArray = malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
|
|---|
| 867 | memPtr=pmmFormatInfoArray;
|
|---|
| 868 | if( pmmFormatInfoArray == NULL )
|
|---|
| 869 | {
|
|---|
| 870 | /*
|
|---|
| 871 | * Could not allocate enough memory for mmFormatInfo array.
|
|---|
| 872 | */
|
|---|
| 873 | return FALSE;
|
|---|
| 874 | }
|
|---|
| 875 |
|
|---|
| 876 | /*
|
|---|
| 877 | * call mmioGetFormats to get info on the formats supported.
|
|---|
| 878 | */
|
|---|
| 879 | ulReturnCode = mmioGetFormats( &mmFormatInfo,
|
|---|
| 880 | lNumIOProcs,
|
|---|
| 881 | pmmFormatInfoArray,
|
|---|
| 882 | &lFormatsRead,
|
|---|
| 883 | 0,
|
|---|
| 884 | 0 );
|
|---|
| 885 | if( ulReturnCode != MMIO_SUCCESS )
|
|---|
| 886 | {
|
|---|
| 887 | /*
|
|---|
| 888 | * mmioGetFormats failed.
|
|---|
| 889 | */
|
|---|
| 890 | free(pmmFormatInfoArray);
|
|---|
| 891 | return FALSE;
|
|---|
| 892 | }
|
|---|
| 893 |
|
|---|
| 894 | if( lFormatsRead != lNumIOProcs )
|
|---|
| 895 | {
|
|---|
| 896 | /*
|
|---|
| 897 | * Error in MMIO - number of formats read in by
|
|---|
| 898 | * mmioGetFormats is not equal to number of formats
|
|---|
| 899 | * found by mmioQueryFormatCount.
|
|---|
| 900 | */
|
|---|
| 901 | free(pmmFormatInfoArray);
|
|---|
| 902 | return FALSE;
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | for ( index = 0; index <lNumIOProcs; index++ )
|
|---|
| 906 | {
|
|---|
| 907 | /* Now scan the whole image proc array */
|
|---|
| 908 | if(!strstr(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt)) {
|
|---|
| 909 | /* This extension is yet unknown */
|
|---|
| 910 | if(chrMMImageKnownExt[0]==0) {
|
|---|
| 911 | /* It's the first one */
|
|---|
| 912 | sprintf(chrMMImageKnownExt,"*.%s", pmmFormatInfoArray->szDefaultFormatExt);
|
|---|
| 913 | }
|
|---|
| 914 | else {
|
|---|
| 915 | /* Check if the extension is not already added (e.g. TIF has a lot of subformats) */
|
|---|
| 916 | if(!strstr(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt)) {
|
|---|
| 917 | strlcat(chrMMImageKnownExt,";*.", ulSize);
|
|---|
| 918 | strlcat(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt, ulSize);
|
|---|
| 919 | }
|
|---|
| 920 | }
|
|---|
| 921 | }
|
|---|
| 922 | /*
|
|---|
| 923 | * advance to next entry in mmFormatInfo array
|
|---|
| 924 | */
|
|---|
| 925 | pmmFormatInfoArray++;
|
|---|
| 926 | }
|
|---|
| 927 | free(memPtr);
|
|---|
| 928 | return FALSE;
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 | int main (int argc, char *argv[])
|
|---|
| 933 | {
|
|---|
| 934 | HAB hab;
|
|---|
| 935 | HMQ hmq;
|
|---|
| 936 | char text[CCHMAXPATH];
|
|---|
| 937 | short a;
|
|---|
| 938 |
|
|---|
| 939 | /* Create a copy of the args */
|
|---|
| 940 | /* argv[0]: progname
|
|---|
| 941 | */
|
|---|
| 942 |
|
|---|
| 943 | numArgs=argc;
|
|---|
| 944 |
|
|---|
| 945 | strcpy(text,"");
|
|---|
| 946 | for(a=0;a<argc;a++)
|
|---|
| 947 | {
|
|---|
| 948 | params[a]=argv[a];
|
|---|
| 949 | }
|
|---|
| 950 |
|
|---|
| 951 | hab=WinInitialize(0);
|
|---|
| 952 | if(hab) {
|
|---|
| 953 | hmq=WinCreateMsgQueue(hab,0);
|
|---|
| 954 | if(hmq) {
|
|---|
| 955 | /* Check if user started prog by hand */
|
|---|
| 956 | if(argc!=NUMPARAMS) {/* Not the right num of params */
|
|---|
| 957 | pmUsage();
|
|---|
| 958 | }
|
|---|
| 959 | else {
|
|---|
| 960 | HWND hwndDlg;
|
|---|
| 961 |
|
|---|
| 962 | /* Get our ressource dll */
|
|---|
| 963 | RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
|
|---|
| 964 | /* Load NLV strings */
|
|---|
| 965 | loadStringsFromResourceDLL(RESSOURCEHANDLE);
|
|---|
| 966 |
|
|---|
| 967 | /* Get data from INI file */
|
|---|
| 968 | HlpBuildMMProgIniFileName(argv[0], chrIniFile, sizeof(chrIniFile));
|
|---|
| 969 |
|
|---|
| 970 | /* Get additional audio extensions from mmpm2.ini */
|
|---|
| 971 | getStringFromRexxScript(queryExeDir(argv[0]), "audioext.rx",
|
|---|
| 972 | chrAdditionalExt, sizeof(chrAdditionalExt));
|
|---|
| 973 | if(strlen(chrAdditionalExt)!=0) {
|
|---|
| 974 | translateChars(chrAdditionalExt, ',', ';');
|
|---|
| 975 | strlcat(chrMediaFileExt[MT_AUDIO], ";", sizeof(chrMediaFileExt[MT_AUDIO]));
|
|---|
| 976 | strlcat(chrMediaFileExt[MT_AUDIO], chrAdditionalExt, sizeof(chrMediaFileExt[MT_AUDIO]));
|
|---|
| 977 | }
|
|---|
| 978 |
|
|---|
| 979 | /* Get image extensions */
|
|---|
| 980 | getStringFromRexxScript(queryExeDir(argv[0]), "imageext.rx",
|
|---|
| 981 | chrMediaFileExt[MT_IMAGE], sizeof(chrMediaFileExt[MT_IMAGE]));
|
|---|
| 982 | if(strlen(chrMediaFileExt[MT_IMAGE])!=0)
|
|---|
| 983 | translateChars(chrMediaFileExt[MT_IMAGE], ',', ';');
|
|---|
| 984 | /* Get additional image extensions supplied by the user in imageadd.rx */
|
|---|
| 985 | chrAdditionalExt[0]=0;
|
|---|
| 986 | getStringFromRexxScript(queryExeDir(argv[0]), "imageadd.rx",
|
|---|
| 987 | chrAdditionalExt, sizeof(chrAdditionalExt));
|
|---|
| 988 | if(strlen(chrAdditionalExt)!=0) {
|
|---|
| 989 | translateChars(chrAdditionalExt, ',', ';');
|
|---|
| 990 | strlcat(chrMediaFileExt[MT_IMAGE], ";", sizeof(chrMediaFileExt[MT_IMAGE]));
|
|---|
| 991 | strlcat(chrMediaFileExt[MT_IMAGE], chrAdditionalExt, sizeof(chrMediaFileExt[MT_IMAGE]));
|
|---|
| 992 | }
|
|---|
| 993 | /* Get extensions handled by installed IO procs */
|
|---|
| 994 | getMissingExtFromImageIOProc(chrMediaFileExt[MT_IMAGE], sizeof(chrMediaFileExt[MT_IMAGE]));
|
|---|
| 995 |
|
|---|
| 996 | #if 0
|
|---|
| 997 | sprintf(chrInstallDir, "%d!%s!", strlen(chrMediaFileExt[MT_IMAGE]), chrMediaFileExt[MT_IMAGE]);
|
|---|
| 998 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, chrInstallDir, chrMediaFileExt[MT_IMAGE], 1234, MB_OK);
|
|---|
| 999 | #endif
|
|---|
| 1000 |
|
|---|
| 1001 | /* Restore recent visited directories */
|
|---|
| 1002 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastaudiodir", "", chrLastAudioDir, sizeof(chrLastAudioDir));
|
|---|
| 1003 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastvideodir", "", chrLastVideoDir, sizeof(chrLastVideoDir));
|
|---|
| 1004 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastimagedir", "", chrLastImageDir, sizeof(chrLastImageDir));
|
|---|
| 1005 |
|
|---|
| 1006 | _loadButtonBmps();
|
|---|
| 1007 | fd.cbSize = sizeof( fd );
|
|---|
| 1008 | /* It's an centered 'Open'-dialog */
|
|---|
| 1009 | fd.fl = FDS_OPEN_DIALOG|FDS_CENTER | FDS_CUSTOM;
|
|---|
| 1010 | fd.hMod=RESSOURCEHANDLE;
|
|---|
| 1011 | fd.usDlgId=IDDLG_MMFIND;
|
|---|
| 1012 | fd.pfnDlgProc=findFileDlgProc;
|
|---|
| 1013 |
|
|---|
| 1014 |
|
|---|
| 1015 | switch(iMediaType)
|
|---|
| 1016 | {
|
|---|
| 1017 | case MT_AUDIO:
|
|---|
| 1018 | strlcpy(fd.szFullFile, chrLastAudioDir, sizeof(fd.szFullFile));
|
|---|
| 1019 | break;
|
|---|
| 1020 | case MT_IMAGE:
|
|---|
| 1021 | strlcpy(fd.szFullFile, chrLastImageDir, sizeof(fd.szFullFile));
|
|---|
| 1022 | break;
|
|---|
| 1023 | case MT_VIDEO:
|
|---|
| 1024 | strlcpy(fd.szFullFile, chrLastVideoDir, sizeof(fd.szFullFile));
|
|---|
| 1025 | break;
|
|---|
| 1026 | default:
|
|---|
| 1027 | break;
|
|---|
| 1028 | }
|
|---|
| 1029 |
|
|---|
| 1030 | if( (hwndDlg=WinFileDlg( HWND_DESKTOP, HWND_DESKTOP, &fd )) != NULLHANDLE )
|
|---|
| 1031 | {
|
|---|
| 1032 | if(hBitmap)
|
|---|
| 1033 | GpiDeleteBitmap(hBitmap);
|
|---|
| 1034 | if( fd.lReturn == DID_OK )
|
|---|
| 1035 | {
|
|---|
| 1036 | switch(mmIdentifyFile(fd.szFullFile))
|
|---|
| 1037 | {
|
|---|
| 1038 | case MT_IMAGE:
|
|---|
| 1039 | {
|
|---|
| 1040 | HOBJECT hObject;
|
|---|
| 1041 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
|---|
| 1042 | WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
|---|
| 1043 | break;
|
|---|
| 1044 | }
|
|---|
| 1045 | case MT_AUDIO:
|
|---|
| 1046 | {
|
|---|
| 1047 | HOBJECT hObject;
|
|---|
| 1048 |
|
|---|
| 1049 | /* Open the audio file in the editor */
|
|---|
| 1050 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
|---|
| 1051 | WinOpenObject(hObject, ID_MENU_EDITOR, TRUE);
|
|---|
| 1052 | // WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
|---|
| 1053 | break;
|
|---|
| 1054 | }
|
|---|
| 1055 | case MT_VIDEO:
|
|---|
| 1056 | {
|
|---|
| 1057 | HOBJECT hObject;
|
|---|
| 1058 | char *chr;
|
|---|
| 1059 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
|---|
| 1060 | WinOpenObject(hObject, ID_MENU_PLAYER /* OPEN_DEFAULT */, TRUE);
|
|---|
| 1061 | #if 0
|
|---|
| 1062 | /* Open folder */
|
|---|
| 1063 | if((chr=strrchr(fd.szFullFile, '\\'))!=NULLHANDLE) {
|
|---|
| 1064 | *chr=0;
|
|---|
| 1065 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
|---|
| 1066 | WinOpenObject(hObject, OPEN_CONTENTS, TRUE);
|
|---|
| 1067 | }
|
|---|
| 1068 | #endif
|
|---|
| 1069 | break;
|
|---|
| 1070 | }
|
|---|
| 1071 | default:
|
|---|
| 1072 | {
|
|---|
| 1073 | HOBJECT hObject;
|
|---|
| 1074 | char *chr;
|
|---|
| 1075 | if((chr=strrchr(fd.szFullFile, '\\'))!=NULLHANDLE) {
|
|---|
| 1076 | *chr=0;
|
|---|
| 1077 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
|---|
| 1078 | WinOpenObject(hObject, OPEN_CONTENTS, TRUE);
|
|---|
| 1079 | }
|
|---|
| 1080 | break;
|
|---|
| 1081 | }
|
|---|
| 1082 | }/* switch()*/
|
|---|
| 1083 | }/* DID_OK */
|
|---|
| 1084 | /* Save the last visited directories */
|
|---|
| 1085 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastaudiodir", chrLastAudioDir);
|
|---|
| 1086 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastvideodir", chrLastVideoDir);
|
|---|
| 1087 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastimagedir", chrLastImageDir);
|
|---|
| 1088 | }
|
|---|
| 1089 | freeResHandle();
|
|---|
| 1090 | }
|
|---|
| 1091 | WinDestroyMsgQueue(hmq);
|
|---|
| 1092 | }
|
|---|
| 1093 | WinTerminate(hab);
|
|---|
| 1094 | }
|
|---|
| 1095 | return 0;
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|