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