[2] | 1 | /*
|
---|
[4] | 2 | * mmfind.c (C) Chris Wohlgemuth 2004-2005
|
---|
[2] | 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
|
---|
[104] | 23 | *
|
---|
[2] | 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
|
---|
[4] | 39 | #define INCL_REXXSAA
|
---|
[2] | 40 |
|
---|
[4] | 41 | /* OS/2 and compiler includes */
|
---|
[2] | 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>
|
---|
[126] | 48 | #include <rexxsaa.h>
|
---|
[2] | 49 | #include "os2me.h"
|
---|
[4] | 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 */
|
---|
[2] | 57 | #include "common.h"
|
---|
[4] | 58 | #include "mmres.h" /* Ressource IDs */
|
---|
[2] | 59 | #include "mmprogs_defaults.h"
|
---|
[4] | 60 | //#define DEBUG
|
---|
| 61 | #include "mmfind.h" /* mmfind specific defines */
|
---|
[2] | 62 |
|
---|
[4] | 63 | char logName[]="mmfind.log"; /* To keep some (unused) helpers in helper.c happy */
|
---|
[2] | 64 |
|
---|
[4] | 65 | char chrIniFile[CCHMAXPATH];
|
---|
| 66 | char chrInstallDir[CCHMAXPATH];
|
---|
[2] | 67 |
|
---|
[4] | 68 | char chrLastAudioDir[CCHMAXPATH];
|
---|
| 69 | char chrLastVideoDir[CCHMAXPATH];
|
---|
| 70 | char chrLastImageDir[CCHMAXPATH];
|
---|
[2] | 71 |
|
---|
[4] | 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 */
|
---|
[104] | 76 | BOOL bPaused=FALSE;
|
---|
[4] | 77 | ULONG ulPos;
|
---|
| 78 | ULONG ulTotalLength;
|
---|
| 79 | HWND hwndPlayer; /* HWND of the player object window used for async coommunication */
|
---|
[2] | 80 |
|
---|
[4] | 81 | /***************************************/
|
---|
[2] | 82 |
|
---|
| 83 | #define NUMPARAMS 1
|
---|
| 84 | /*
|
---|
| 85 | argv[0]: progname
|
---|
| 86 | */
|
---|
| 87 | int numArgs;
|
---|
| 88 | char* params[NUMPARAMS];
|
---|
| 89 |
|
---|
| 90 | HMODULE RESSOURCEHANDLE=0;
|
---|
| 91 |
|
---|
[4] | 92 | char chrMediaFileTypes[NUMMEDIATYPES][100];
|
---|
[2] | 93 |
|
---|
[4] | 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 */
|
---|
[2] | 96 | "*.BMP;*.DIB;*.GIF;*.JPG;*.PCX;*.PNG;*.PCD;*.TIF;*.TGA;*.VID;*._IM",
|
---|
| 97 | "*.AVI;*.MPG;*.FLI;*.FLC;*.MOV;*.QT;*.VBS"};
|
---|
[4] | 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 |
|
---|
[2] | 103 | int iMediaType=MT_AUDIO;
|
---|
[144] | 104 | static void _loadButtonBmps(void);
|
---|
[2] | 105 |
|
---|
[4] | 106 | /* BMP stuff for preview */
|
---|
[2] | 107 | BITMAPINFOHEADER2 bmpInfoHeader2;
|
---|
| 108 | HBITMAP hBitmap;
|
---|
| 109 |
|
---|
[4] | 110 | /* HBITMAP for the play control buttons */
|
---|
| 111 | HBITMAP hbmPlay;
|
---|
| 112 | HBITMAP hbmStop;
|
---|
| 113 |
|
---|
[2] | 114 | FILEDLG fd = { 0 };
|
---|
| 115 |
|
---|
[4] | 116 | static void _loadButtonBmps()
|
---|
[2] | 117 | {
|
---|
[4] | 118 | HPS hps;
|
---|
| 119 | HMODULE hResource;
|
---|
[2] | 120 |
|
---|
[4] | 121 | hResource=NULLHANDLE;
|
---|
| 122 | hps=WinGetPS(HWND_DESKTOP);
|
---|
| 123 |
|
---|
[104] | 124 | /* Play */
|
---|
[4] | 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);
|
---|
[2] | 131 | }
|
---|
| 132 |
|
---|
[4] | 133 | static void changeButtons(HWND hwnd)
|
---|
[2] | 134 | {
|
---|
[4] | 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;
|
---|
[104] | 147 |
|
---|
[4] | 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;
|
---|
[104] | 167 |
|
---|
[4] | 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);
|
---|
[104] | 203 | if(!MsgGetMessage(chrMediaFileTypes[MT_AUDIO], IDSTR_TYPEAUDIO,
|
---|
[4] | 204 | sizeof(chrMediaFileTypes[MT_AUDIO]), hResMod, HWND_DESKTOP))
|
---|
| 205 | strcpy(chrMediaFileTypes[MT_AUDIO], TEXT_TYPEAUDIO);
|
---|
[104] | 206 | if(!MsgGetMessage(chrMediaFileTypes[MT_IMAGE], IDSTR_TYPEIMAGE,
|
---|
[4] | 207 | sizeof(chrMediaFileTypes[MT_IMAGE]), hResMod, HWND_DESKTOP))
|
---|
| 208 | strcpy(chrMediaFileTypes[MT_AUDIO], TEXT_TYPEIMAGE);
|
---|
[104] | 209 | if(!MsgGetMessage(chrMediaFileTypes[MT_VIDEO], IDSTR_TYPEVIDEO,
|
---|
[4] | 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 | {
|
---|
[2] | 216 | /* Preview area */
|
---|
| 217 | WinShowWindow(WinWindowFromID(hwnd, IDST_NOPREVIEWAVAILABLE), bShow);
|
---|
| 218 | /* Group box */
|
---|
| 219 | WinShowWindow(WinWindowFromID(hwnd, IDGB_PREVIEW), bShow);
|
---|
| 220 | }
|
---|
| 221 |
|
---|
[4] | 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 |
|
---|
[2] | 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);
|
---|
[4] | 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 | }
|
---|
[2] | 246 | }
|
---|
| 247 |
|
---|
[4] | 248 | BOOL pauseAudioFile(HWND hwndNotify)
|
---|
| 249 | {
|
---|
| 250 | #if 0
|
---|
| 251 | char chrCommand[50];
|
---|
| 252 | char retMsg[100];
|
---|
| 253 | ULONG rc;
|
---|
[2] | 254 |
|
---|
[4] | 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)
|
---|
[2] | 273 | {
|
---|
[4] | 274 | char chrCommand[50];
|
---|
| 275 | char retMsg[100];
|
---|
| 276 |
|
---|
| 277 | if(bIsPlaying) {
|
---|
| 278 | sprintf(chrCommand,"stop wave%ld wait", hwndNotify);
|
---|
[104] | 279 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
| 280 |
|
---|
[4] | 281 | sprintf(chrCommand,"close wave%ld wait", hwndNotify);
|
---|
[104] | 282 | mciSendString(chrCommand, retMsg, sizeof(retMsg), 0, 0);
|
---|
[4] | 283 |
|
---|
[104] | 284 | #if 0
|
---|
[4] | 285 | _resetDisplay(hwndFrame);
|
---|
| 286 | showPlayTimeDisplay( hwndFrame, TRUE);
|
---|
| 287 | WinStopTimer(WinQueryAnchorBlock(hwndFrame), hwndFrame, IDTIMER_PLAY);
|
---|
| 288 | #endif
|
---|
| 289 | bIsPlaying=FALSE;
|
---|
[104] | 290 | bPaused=FALSE;
|
---|
[4] | 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)
|
---|
[142] | 318 | strncpy(chrDevice,"SEQUENCER", sizeof(chrDevice) - 1);
|
---|
[4] | 319 | else
|
---|
[142] | 320 | strncpy(chrDevice,"WAVEAUDIO", sizeof(chrDevice) - 1);
|
---|
[4] | 321 |
|
---|
[104] | 322 | /* Start audio file */
|
---|
[4] | 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;
|
---|
[104] | 329 |
|
---|
[4] | 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;
|
---|
[104] | 337 | }
|
---|
[4] | 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 */
|
---|
[104] | 423 | void playThreadFunc (void *arg)
|
---|
[4] | 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 | {
|
---|
[2] | 485 | MMIOINFO mmioInfo={0};
|
---|
| 486 | MMFORMATINFO mmFormatInfo={0};
|
---|
| 487 | FOURCC fourCC;
|
---|
| 488 |
|
---|
| 489 | if(MMIO_SUCCESS!=mmioIdentifyFile(chrFile, &mmioInfo, &mmFormatInfo, &fourCC, 0,0))
|
---|
| 490 | {
|
---|
[104] | 491 | return MT_UNKNOWN;
|
---|
[2] | 492 | }
|
---|
| 493 |
|
---|
| 494 | switch(mmFormatInfo.ulMediaType)
|
---|
| 495 | {
|
---|
| 496 | case MMIO_MEDIATYPE_MIDI: /* Midi */
|
---|
[218] | 497 | bIsMidi = TRUE;
|
---|
| 498 | return MT_AUDIO;
|
---|
[2] | 499 | case MMIO_MEDIATYPE_AUDIO: /* Any other audio file */
|
---|
[218] | 500 | bIsMidi = FALSE;
|
---|
[2] | 501 | return MT_AUDIO;
|
---|
| 502 | case MMIO_MEDIATYPE_IMAGE:
|
---|
| 503 | return MT_IMAGE;
|
---|
| 504 | case MMIO_MEDIATYPE_DIGITALVIDEO:
|
---|
| 505 | case MMIO_MEDIATYPE_MOVIE:
|
---|
| 506 | return MT_VIDEO;
|
---|
| 507 | default:
|
---|
| 508 | return MT_UNKNOWN;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | return 0;
|
---|
| 512 | }
|
---|
| 513 |
|
---|
[4] | 514 | static PSZ queryExeDir(const char *chrEXE)
|
---|
| 515 | {
|
---|
| 516 | if(chrInstallDir[0]==0)
|
---|
| 517 | {
|
---|
| 518 | char * chr;
|
---|
| 519 | strlcpy(chrInstallDir, chrEXE, sizeof(chrInstallDir));
|
---|
| 520 | if((chr=strrchr(chrInstallDir, '\\'))!=NULLHANDLE)
|
---|
| 521 | *chr='\0';
|
---|
| 522 | }
|
---|
| 523 | return chrInstallDir;
|
---|
| 524 | }
|
---|
[2] | 525 |
|
---|
[4] | 526 |
|
---|
[144] | 527 | MRESULT EXPENTRY findFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[2] | 528 | {
|
---|
| 529 |
|
---|
| 530 | switch(msg)
|
---|
| 531 | {
|
---|
| 532 | case WM_INITDLG:
|
---|
| 533 | {
|
---|
| 534 | int a;
|
---|
[4] | 535 | SWCNTRL swctl;
|
---|
| 536 | PID pid;
|
---|
[2] | 537 |
|
---|
| 538 | /* Set dialog font */
|
---|
| 539 | if(SysQueryOSRelease()>=40) {
|
---|
| 540 | WinSetPresParam(hwnd,
|
---|
| 541 | PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
|
---|
| 542 | DEFAULT_DIALOG_FONT );
|
---|
| 543 | }
|
---|
| 544 | /* Fill combo box with media types (audio, image, video) */
|
---|
[104] | 545 | for(a=0;a<NUMMEDIATYPES;a++)
|
---|
| 546 | WinSendMsg(WinWindowFromID(hwnd, IDCB_TYPEOFFILE), LM_INSERTITEM, MRFROMSHORT(LIT_SORTASCENDING),
|
---|
[2] | 547 | MPFROMP(chrMediaFileTypes[a]));
|
---|
| 548 | WinSetWindowText(WinWindowFromID(hwnd, IDCB_TYPEOFFILE), chrMediaFileTypes[0]);
|
---|
| 549 |
|
---|
| 550 | /* Subclass preview area */
|
---|
| 551 | WinSubclassWindow(WinWindowFromID(hwnd, IDSR_IMGPREVIEW), bmpPreviewProc);
|
---|
[4] | 552 |
|
---|
| 553 | /* Add switch entry */
|
---|
| 554 | memset(&swctl,0,sizeof(swctl));
|
---|
| 555 | WinQueryWindowProcess(hwnd,&pid,NULL);
|
---|
| 556 | swctl.hwnd=hwnd;
|
---|
| 557 | swctl.uchVisibility=SWL_VISIBLE;
|
---|
| 558 | swctl.idProcess=pid;
|
---|
| 559 | swctl.bProgType=PROG_DEFAULT;
|
---|
| 560 | swctl.fbJump=SWL_JUMPABLE;
|
---|
| 561 | WinAddSwitchEntry(&swctl);
|
---|
| 562 |
|
---|
| 563 | /* Add bitmap to play control buttons */
|
---|
| 564 | changeButtons(hwnd);
|
---|
| 565 |
|
---|
| 566 | /* Start an audio player thread */
|
---|
| 567 | MMAudioOpenPlayer(hwnd);
|
---|
[2] | 568 | break;
|
---|
| 569 | }
|
---|
[4] | 570 | case WM_APPTERMINATENOTIFY:
|
---|
| 571 | {
|
---|
| 572 | /* Posted from player object window */
|
---|
| 573 | switch(SHORT1FROMMP(mp1))
|
---|
| 574 | {
|
---|
| 575 | case MMAUDIO_PLAYER_CREATED:
|
---|
| 576 | /* Player object window */
|
---|
| 577 | hwndPlayer=HWNDFROMMP(mp2);
|
---|
| 578 | break;
|
---|
| 579 | default:
|
---|
| 580 | break;
|
---|
| 581 | }
|
---|
| 582 | return MRFALSE;
|
---|
| 583 | }
|
---|
[2] | 584 | case WM_CONTROL:
|
---|
| 585 | {
|
---|
| 586 | switch(SHORT1FROMMP(mp1))
|
---|
| 587 | {
|
---|
| 588 | case IDCB_TYPEOFFILE:
|
---|
| 589 | {
|
---|
| 590 | if(SHORT2FROMMP(mp1)==CBN_EFCHANGE) {
|
---|
| 591 | char chrText[100];
|
---|
| 592 | int a;
|
---|
| 593 | WinQueryWindowText(HWNDFROMMP(mp2), sizeof(chrText), chrText);
|
---|
| 594 | /* Find Index */
|
---|
[4] | 595 | for(a=0; a<NUMMEDIATYPES;a++) {
|
---|
[2] | 596 | if(!stricmp(chrMediaFileTypes[a], chrText))
|
---|
| 597 | break;
|
---|
| 598 | }
|
---|
| 599 | /* Error!??!*/
|
---|
| 600 | switch(a)
|
---|
| 601 | {
|
---|
| 602 | case 0: /* Audio */
|
---|
| 603 | {
|
---|
| 604 | showVideoControls(hwnd, FALSE);
|
---|
| 605 | showImageControls(hwnd, FALSE);
|
---|
| 606 | showAudioControls(hwnd, TRUE);
|
---|
| 607 | iMediaType=MT_AUDIO;
|
---|
| 608 | break;
|
---|
| 609 | }
|
---|
| 610 | case 1: /* Image */
|
---|
| 611 | showAudioControls(hwnd, FALSE);
|
---|
| 612 | showVideoControls(hwnd, FALSE);
|
---|
| 613 | showImageControls(hwnd, TRUE);
|
---|
[4] | 614 | iMediaType=MT_IMAGE;
|
---|
[2] | 615 | break;
|
---|
| 616 | case 2:
|
---|
| 617 | showAudioControls(hwnd, FALSE);
|
---|
| 618 | showImageControls(hwnd, FALSE);
|
---|
| 619 | showVideoControls(hwnd, TRUE);
|
---|
| 620 | iMediaType=MT_VIDEO;
|
---|
| 621 | break;
|
---|
| 622 | default:
|
---|
| 623 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
---|
| 624 | }
|
---|
| 625 | WinSetWindowText(WinWindowFromID(hwnd, 258), chrMediaFileExt[a]);
|
---|
| 626 | WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, 258));
|
---|
| 627 | WinSendMsg(WinWindowFromID(hwnd, 258), WM_CHAR,
|
---|
| 628 | MPFROM2SHORT(KC_VIRTUALKEY , 0), MPFROM2SHORT(0, VK_NEWLINE));
|
---|
| 629 | }
|
---|
| 630 | break;
|
---|
| 631 | }
|
---|
| 632 | case 258:
|
---|
| 633 | {
|
---|
| 634 | if(SHORT2FROMMP(mp1)==EN_CHANGE)
|
---|
[4] | 635 | WinStartTimer(WinQueryAnchorBlock(HWND_DESKTOP), hwnd, TIMERID_SELECTION, 100);
|
---|
[2] | 636 | break;
|
---|
| 637 | }
|
---|
| 638 | default:
|
---|
| 639 | break;
|
---|
| 640 | }
|
---|
| 641 | break;
|
---|
| 642 | }
|
---|
| 643 | case WM_TIMER:
|
---|
| 644 | switch(SHORT1FROMMP(mp1))
|
---|
| 645 | {
|
---|
| 646 | case TIMERID_SELECTION:
|
---|
| 647 | {
|
---|
| 648 | char chrName[CCHMAXPATH];
|
---|
| 649 | char chrFullName[CCHMAXPATH*2];
|
---|
| 650 |
|
---|
[4] | 651 | WinStopTimer(WinQueryAnchorBlock(HWND_DESKTOP), hwnd, TIMERID_SELECTION);
|
---|
[2] | 652 | WinQueryWindowText(WinWindowFromID(hwnd, 258), sizeof(chrName), chrName);
|
---|
| 653 | strcpy(chrFullName, fd.szFullFile);
|
---|
[4] | 654 | switch(iMediaType)
|
---|
| 655 | {
|
---|
| 656 | case MT_AUDIO:
|
---|
| 657 | strlcpy(chrLastAudioDir, fd.szFullFile, sizeof(chrLastAudioDir));
|
---|
| 658 | break;
|
---|
| 659 | case MT_IMAGE:
|
---|
| 660 | strlcpy(chrLastImageDir, fd.szFullFile, sizeof(chrLastImageDir));
|
---|
| 661 | break;
|
---|
| 662 | case MT_VIDEO:
|
---|
| 663 | strlcpy(chrLastImageDir, fd.szFullFile, sizeof(chrLastImageDir));
|
---|
| 664 | break;
|
---|
| 665 | default:
|
---|
| 666 | break;
|
---|
| 667 | }
|
---|
[2] | 668 | strcat(chrFullName, chrName);
|
---|
[4] | 669 | strlcpy(chrSourceName, chrFullName, sizeof(chrSourceName));
|
---|
[2] | 670 | switch(iMediaType)
|
---|
| 671 | {
|
---|
| 672 | case MT_AUDIO:
|
---|
| 673 | {
|
---|
| 674 | char text[500];
|
---|
| 675 | MMIOINFO mmio;
|
---|
| 676 | HMMIO hmmio;
|
---|
| 677 | MMAUDIOHEADER mmAudioHeader={0};
|
---|
| 678 | LONG lBytesRead=0;
|
---|
| 679 | ULONG rc;
|
---|
| 680 | ULONG ulPlaySecs;
|
---|
| 681 |
|
---|
[4] | 682 | MMAudioStop(hwndPlayer, hwnd);
|
---|
| 683 |
|
---|
[2] | 684 | memset(&mmio,0, sizeof(mmio));
|
---|
| 685 | mmio.ulFlags=MMIO_READ;
|
---|
| 686 | mmio.ulTranslate=MMIO_TRANSLATEHEADER;
|
---|
[104] | 687 |
|
---|
[2] | 688 | hmmio = mmioOpen(chrFullName, &mmio, MMIO_READ);
|
---|
| 689 | if(!hmmio)
|
---|
| 690 | break;
|
---|
| 691 |
|
---|
| 692 | memset(&mmAudioHeader,0,sizeof(MMAUDIOHEADER));
|
---|
| 693 | rc = mmioGetHeader(hmmio, &mmAudioHeader,sizeof(MMAUDIOHEADER),
|
---|
| 694 | &lBytesRead, 0, 0);
|
---|
[104] | 695 |
|
---|
[2] | 696 | mmioClose(hmmio, 0);
|
---|
| 697 | if(rc!=MMIO_SUCCESS) {
|
---|
| 698 | WinSetWindowText(WinWindowFromID(hwnd, IDST_AUDIOINFO), "");
|
---|
[4] | 699 | enableAudioPlayControls(hwnd, FALSE);
|
---|
[2] | 700 | break;
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | ulPlaySecs=mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInMS/1000;
|
---|
[4] | 704 | sprintf(text, audioText, ulPlaySecs/60, ulPlaySecs%60,
|
---|
[2] | 705 | mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec,
|
---|
| 706 | mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample,
|
---|
| 707 | mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels);
|
---|
| 708 | WinSetWindowText(WinWindowFromID(hwnd, IDST_AUDIOINFO), text);
|
---|
[4] | 709 | enableAudioPlayControls(hwnd, TRUE);
|
---|
[2] | 710 | break;
|
---|
| 711 | }
|
---|
| 712 | case MT_IMAGE:
|
---|
| 713 | if(hBitmap) {
|
---|
| 714 | HBITMAP hBitmapTemp;
|
---|
[4] | 715 | // hBitmapTemp=loadBitmap (chrFullName, &bmpInfoHeader2);
|
---|
| 716 | hBitmapTemp=ImgLoadImageFileAndHeader(chrFullName, &bmpInfoHeader2);
|
---|
[2] | 717 | GpiDeleteBitmap(hBitmap);
|
---|
| 718 | hBitmap=hBitmapTemp;
|
---|
| 719 | }
|
---|
| 720 | else
|
---|
[4] | 721 | hBitmap=ImgLoadImageFileAndHeader(chrFullName, &bmpInfoHeader2);
|
---|
| 722 | // hBitmap=loadBitmap (chrFullName, &bmpInfoHeader2);
|
---|
[2] | 723 | /* Force redraw of preview area */
|
---|
| 724 | WinInvalidateRect(WinWindowFromID(hwnd, IDSR_IMGPREVIEW), NULLHANDLE, FALSE);
|
---|
| 725 | break;
|
---|
| 726 | case MT_VIDEO:
|
---|
| 727 | break;
|
---|
| 728 | default:
|
---|
| 729 | break;
|
---|
| 730 | }
|
---|
| 731 | return MRFALSE;
|
---|
| 732 | }
|
---|
| 733 | default:
|
---|
| 734 | break;
|
---|
| 735 | }
|
---|
| 736 | case WM_COMMAND:
|
---|
| 737 | switch(SHORT1FROMMP(mp1))
|
---|
| 738 | {
|
---|
[4] | 739 | case IDPB_MMFINDPLAY:
|
---|
| 740 | {
|
---|
| 741 | MMAudioPlayFile(hwndPlayer, hwnd, NULLHANDLE);
|
---|
| 742 | return MRFALSE;
|
---|
| 743 | }
|
---|
| 744 | case IDPB_MMFINDSTOP:
|
---|
| 745 | {
|
---|
| 746 | MMAudioStop(hwndPlayer, hwnd);
|
---|
| 747 | return MRFALSE;
|
---|
| 748 | }
|
---|
| 749 | case IDPB_MMFINDPAUSE:
|
---|
| 750 | {
|
---|
| 751 | MMAudioPause(hwndPlayer, hwnd);
|
---|
| 752 | return MRFALSE;
|
---|
| 753 | }
|
---|
[2] | 754 | case IDPB_NEWFILE: /* New */
|
---|
| 755 | {
|
---|
| 756 | HOBJECT hObject;
|
---|
[4] | 757 |
|
---|
| 758 | MMAudioStop(hwndPlayer, hwnd);
|
---|
| 759 | MMAudioClosePlayer(hwndPlayer);
|
---|
| 760 |
|
---|
| 761 | /* Open the MM templates folder */
|
---|
[2] | 762 | if((hObject=WinQueryObject("<MMPM2_MMTEMPLATEFOLDER>"))!=NULLHANDLE) {
|
---|
| 763 | WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
---|
| 764 | WinDismissDlg(hwnd, DID_CANCEL);
|
---|
| 765 | }
|
---|
| 766 | else
|
---|
[4] | 767 | MsgShowMessageBox(hwnd, IDSTR_NOMMTEMPLATEFLDRTITLE, IDSTR_NOMMTEMPLATEFLDR,
|
---|
| 768 | RESSOURCEHANDLE, MB_MOVEABLE|MB_OK);
|
---|
[2] | 769 | return MRFALSE;
|
---|
| 770 | }
|
---|
| 771 | default:
|
---|
[4] | 772 | // MMAudioStop(hwndPlayer, hwnd);
|
---|
| 773 | stopAudioFile(hwnd);
|
---|
| 774 | MMAudioClosePlayer(hwndPlayer);
|
---|
| 775 | // DosSleep(1000);
|
---|
[2] | 776 | break;
|
---|
| 777 | }
|
---|
| 778 | default:
|
---|
| 779 | break;
|
---|
| 780 | }
|
---|
| 781 | return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
|
---|
| 782 | }
|
---|
| 783 |
|
---|
[4] | 784 | BOOL getStringFromRexxScript(PSZ pszBinDir, PSZ rexxFile, char* chrResult, ULONG ulSize)
|
---|
| 785 | {
|
---|
| 786 |
|
---|
| 787 | RXSTRING arg[1]; /* argument string for REXX */
|
---|
| 788 | RXSTRING rexxretval; /* return value from REXX */
|
---|
| 789 | APIRET rc; /* return code from REXX */
|
---|
| 790 | SHORT rexxrc = 0; /* return code from function */
|
---|
[104] | 791 | char theScript[CCHMAXPATH];
|
---|
[4] | 792 | /* By setting the strlength of the output RXSTRING to zero, we */
|
---|
| 793 | /* force the interpreter to allocate memory and return it to us. */
|
---|
| 794 | /* We could provide a buffer for the interpreter to use instead. */
|
---|
| 795 | rexxretval.strlength = 0L; /* initialize return to empty*/
|
---|
[104] | 796 |
|
---|
[4] | 797 | sprintf(theScript, "%s\\%s", pszBinDir, rexxFile);
|
---|
| 798 |
|
---|
| 799 | /* Here we call the interpreter. We don't really need to use */
|
---|
| 800 | /* all the casts in this call; they just help illustrate */
|
---|
| 801 | /* the data types used. */
|
---|
| 802 | rc=RexxStart((LONG) 0, /* number of arguments */
|
---|
| 803 | (PRXSTRING) &arg, /* array of arguments */
|
---|
| 804 | (PSZ) theScript, /* name of REXX file */
|
---|
| 805 | (PRXSTRING) 0, /* No INSTORE used */
|
---|
| 806 | (PSZ) "CWRXX", /* Command env. name */
|
---|
| 807 | (LONG) RXSUBROUTINE, /* Code for how invoked */
|
---|
| 808 | (PRXSYSEXIT) 0, /* No EXITs on this call */
|
---|
| 809 | (PSHORT) &rexxrc, /* Rexx program output */
|
---|
| 810 | (PRXSTRING) &rexxretval ); /* Rexx program output */
|
---|
| 811 | #if 0
|
---|
| 812 | if(rc) {
|
---|
[104] | 813 | sprintf(text,"Error in the Rexx skript %s\n\n Get more information with 'help REX%04d'.\n",
|
---|
[4] | 814 | tPt->rexxSkript, rc*-1);
|
---|
| 815 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE|MB_ERROR);
|
---|
| 816 | }
|
---|
| 817 | #endif
|
---|
| 818 | if(!rc) {
|
---|
| 819 | if(ulSize>rexxretval.strlength) {
|
---|
| 820 | strncpy(chrResult, rexxretval.strptr, rexxretval.strlength);
|
---|
| 821 | chrResult[rexxretval.strlength]=0;
|
---|
| 822 | }
|
---|
| 823 | else
|
---|
| 824 | strncpy(chrResult, rexxretval.strptr, ulSize);
|
---|
| 825 | chrResult[ulSize-1]=0;
|
---|
| 826 | }
|
---|
| 827 | if(rexxretval.strptr)
|
---|
[104] | 828 | DosFreeMem(rexxretval.strptr); /* Release storage given to us by REXX. */
|
---|
[4] | 829 | if(!rc)
|
---|
| 830 | return TRUE;
|
---|
| 831 | else
|
---|
| 832 | return FALSE;
|
---|
| 833 | }
|
---|
| 834 | /*
|
---|
| 835 | This function checks the installed image IO procs and adds extensions which are not yet handled
|
---|
| 836 | to the list of known extensions.
|
---|
| 837 | */
|
---|
| 838 | static BOOL getMissingExtFromImageIOProc(char *chrMMImageKnownExt, ULONG ulSize)
|
---|
| 839 | {
|
---|
| 840 | MMFORMATINFO mmFormatInfo;
|
---|
| 841 | PMMFORMATINFO pmmFormatInfoArray;
|
---|
| 842 | void * memPtr;
|
---|
| 843 | ULONG ulReturnCode;
|
---|
| 844 | LONG lFormatsRead;
|
---|
| 845 | LONG index;
|
---|
| 846 | LONG lNumIOProcs;
|
---|
| 847 |
|
---|
| 848 | memset( &mmFormatInfo,
|
---|
| 849 | '\0',
|
---|
| 850 | sizeof(MMFORMATINFO) );
|
---|
[104] | 851 |
|
---|
[4] | 852 | mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
|
---|
[104] | 853 | mmFormatInfo.ulFlags|=MMIO_CANREADTRANSLATED;/* Read !!!*/
|
---|
[4] | 854 | ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
|
---|
| 855 | &lNumIOProcs,
|
---|
| 856 | 0,
|
---|
| 857 | 0 );
|
---|
[104] | 858 |
|
---|
[4] | 859 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
| 860 | {
|
---|
| 861 | /*
|
---|
| 862 | * Error - mmioQueryFormatCount failed.
|
---|
| 863 | */
|
---|
| 864 | return FALSE;
|
---|
| 865 | }
|
---|
| 866 |
|
---|
| 867 | /*
|
---|
| 868 | * Allocate enough memory for n number of FormatInfo blocks
|
---|
| 869 | */
|
---|
| 870 | pmmFormatInfoArray = malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
|
---|
| 871 | memPtr=pmmFormatInfoArray;
|
---|
| 872 | if( pmmFormatInfoArray == NULL )
|
---|
| 873 | {
|
---|
| 874 | /*
|
---|
| 875 | * Could not allocate enough memory for mmFormatInfo array.
|
---|
| 876 | */
|
---|
| 877 | return FALSE;
|
---|
| 878 | }
|
---|
[104] | 879 |
|
---|
[4] | 880 | /*
|
---|
| 881 | * call mmioGetFormats to get info on the formats supported.
|
---|
| 882 | */
|
---|
| 883 | ulReturnCode = mmioGetFormats( &mmFormatInfo,
|
---|
| 884 | lNumIOProcs,
|
---|
| 885 | pmmFormatInfoArray,
|
---|
| 886 | &lFormatsRead,
|
---|
| 887 | 0,
|
---|
| 888 | 0 );
|
---|
| 889 | if( ulReturnCode != MMIO_SUCCESS )
|
---|
| 890 | {
|
---|
| 891 | /*
|
---|
| 892 | * mmioGetFormats failed.
|
---|
| 893 | */
|
---|
| 894 | free(pmmFormatInfoArray);
|
---|
| 895 | return FALSE;
|
---|
| 896 | }
|
---|
[104] | 897 |
|
---|
[4] | 898 | if( lFormatsRead != lNumIOProcs )
|
---|
| 899 | {
|
---|
| 900 | /*
|
---|
| 901 | * Error in MMIO - number of formats read in by
|
---|
| 902 | * mmioGetFormats is not equal to number of formats
|
---|
| 903 | * found by mmioQueryFormatCount.
|
---|
| 904 | */
|
---|
| 905 | free(pmmFormatInfoArray);
|
---|
| 906 | return FALSE;
|
---|
| 907 | }
|
---|
| 908 |
|
---|
| 909 | for ( index = 0; index <lNumIOProcs; index++ )
|
---|
| 910 | {
|
---|
| 911 | /* Now scan the whole image proc array */
|
---|
| 912 | if(!strstr(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt)) {
|
---|
| 913 | /* This extension is yet unknown */
|
---|
| 914 | if(chrMMImageKnownExt[0]==0) {
|
---|
| 915 | /* It's the first one */
|
---|
| 916 | sprintf(chrMMImageKnownExt,"*.%s", pmmFormatInfoArray->szDefaultFormatExt);
|
---|
| 917 | }
|
---|
| 918 | else {
|
---|
| 919 | /* Check if the extension is not already added (e.g. TIF has a lot of subformats) */
|
---|
| 920 | if(!strstr(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt)) {
|
---|
| 921 | strlcat(chrMMImageKnownExt,";*.", ulSize);
|
---|
| 922 | strlcat(chrMMImageKnownExt, pmmFormatInfoArray->szDefaultFormatExt, ulSize);
|
---|
| 923 | }
|
---|
| 924 | }
|
---|
[104] | 925 | }
|
---|
[4] | 926 | /*
|
---|
| 927 | * advance to next entry in mmFormatInfo array
|
---|
[104] | 928 | */
|
---|
[4] | 929 | pmmFormatInfoArray++;
|
---|
| 930 | }
|
---|
| 931 | free(memPtr);
|
---|
| 932 | return FALSE;
|
---|
| 933 | }
|
---|
| 934 |
|
---|
| 935 |
|
---|
[2] | 936 | int main (int argc, char *argv[])
|
---|
| 937 | {
|
---|
| 938 | HAB hab;
|
---|
| 939 | HMQ hmq;
|
---|
| 940 | char text[CCHMAXPATH];
|
---|
| 941 | short a;
|
---|
| 942 |
|
---|
| 943 | /* Create a copy of the args */
|
---|
| 944 | /* argv[0]: progname
|
---|
| 945 | */
|
---|
| 946 |
|
---|
| 947 | numArgs=argc;
|
---|
| 948 |
|
---|
| 949 | strcpy(text,"");
|
---|
| 950 | for(a=0;a<argc;a++)
|
---|
| 951 | {
|
---|
| 952 | params[a]=argv[a];
|
---|
| 953 | }
|
---|
| 954 |
|
---|
| 955 | hab=WinInitialize(0);
|
---|
| 956 | if(hab) {
|
---|
| 957 | hmq=WinCreateMsgQueue(hab,0);
|
---|
[104] | 958 | if(hmq) {
|
---|
| 959 | /* Check if user started prog by hand */
|
---|
[2] | 960 | if(argc!=NUMPARAMS) {/* Not the right num of params */
|
---|
| 961 | pmUsage();
|
---|
| 962 | }
|
---|
| 963 | else {
|
---|
[104] | 964 | HWND hwndDlg;
|
---|
[2] | 965 |
|
---|
[104] | 966 | /* Get our ressource dll */
|
---|
[2] | 967 | RESSOURCEHANDLE=queryResModuleHandle(argv[0]);
|
---|
[4] | 968 | /* Load NLV strings */
|
---|
| 969 | loadStringsFromResourceDLL(RESSOURCEHANDLE);
|
---|
| 970 |
|
---|
[2] | 971 | /* Get data from INI file */
|
---|
| 972 | HlpBuildMMProgIniFileName(argv[0], chrIniFile, sizeof(chrIniFile));
|
---|
| 973 |
|
---|
[4] | 974 | /* Get additional audio extensions from mmpm2.ini */
|
---|
| 975 | getStringFromRexxScript(queryExeDir(argv[0]), "audioext.rx",
|
---|
| 976 | chrAdditionalExt, sizeof(chrAdditionalExt));
|
---|
| 977 | if(strlen(chrAdditionalExt)!=0) {
|
---|
| 978 | translateChars(chrAdditionalExt, ',', ';');
|
---|
| 979 | strlcat(chrMediaFileExt[MT_AUDIO], ";", sizeof(chrMediaFileExt[MT_AUDIO]));
|
---|
| 980 | strlcat(chrMediaFileExt[MT_AUDIO], chrAdditionalExt, sizeof(chrMediaFileExt[MT_AUDIO]));
|
---|
| 981 | }
|
---|
[2] | 982 |
|
---|
[4] | 983 | /* Get image extensions */
|
---|
| 984 | getStringFromRexxScript(queryExeDir(argv[0]), "imageext.rx",
|
---|
| 985 | chrMediaFileExt[MT_IMAGE], sizeof(chrMediaFileExt[MT_IMAGE]));
|
---|
| 986 | if(strlen(chrMediaFileExt[MT_IMAGE])!=0)
|
---|
| 987 | translateChars(chrMediaFileExt[MT_IMAGE], ',', ';');
|
---|
| 988 | /* Get additional image extensions supplied by the user in imageadd.rx */
|
---|
| 989 | chrAdditionalExt[0]=0;
|
---|
| 990 | getStringFromRexxScript(queryExeDir(argv[0]), "imageadd.rx",
|
---|
| 991 | chrAdditionalExt, sizeof(chrAdditionalExt));
|
---|
| 992 | if(strlen(chrAdditionalExt)!=0) {
|
---|
| 993 | translateChars(chrAdditionalExt, ',', ';');
|
---|
| 994 | strlcat(chrMediaFileExt[MT_IMAGE], ";", sizeof(chrMediaFileExt[MT_IMAGE]));
|
---|
| 995 | strlcat(chrMediaFileExt[MT_IMAGE], chrAdditionalExt, sizeof(chrMediaFileExt[MT_IMAGE]));
|
---|
| 996 | }
|
---|
| 997 | /* Get extensions handled by installed IO procs */
|
---|
| 998 | getMissingExtFromImageIOProc(chrMediaFileExt[MT_IMAGE], sizeof(chrMediaFileExt[MT_IMAGE]));
|
---|
| 999 |
|
---|
| 1000 | #if 0
|
---|
| 1001 | sprintf(chrInstallDir, "%d!%s!", strlen(chrMediaFileExt[MT_IMAGE]), chrMediaFileExt[MT_IMAGE]);
|
---|
| 1002 | WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, chrInstallDir, chrMediaFileExt[MT_IMAGE], 1234, MB_OK);
|
---|
| 1003 | #endif
|
---|
| 1004 |
|
---|
| 1005 | /* Restore recent visited directories */
|
---|
| 1006 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastaudiodir", "", chrLastAudioDir, sizeof(chrLastAudioDir));
|
---|
| 1007 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastvideodir", "", chrLastVideoDir, sizeof(chrLastVideoDir));
|
---|
| 1008 | PrfQueryString(NULLHANDLE, chrIniFile, "mmfind", "lastimagedir", "", chrLastImageDir, sizeof(chrLastImageDir));
|
---|
| 1009 |
|
---|
| 1010 | _loadButtonBmps();
|
---|
[2] | 1011 | fd.cbSize = sizeof( fd );
|
---|
| 1012 | /* It's an centered 'Open'-dialog */
|
---|
| 1013 | fd.fl = FDS_OPEN_DIALOG|FDS_CENTER | FDS_CUSTOM;
|
---|
| 1014 | fd.hMod=RESSOURCEHANDLE;
|
---|
| 1015 | fd.usDlgId=IDDLG_MMFIND;
|
---|
| 1016 | fd.pfnDlgProc=findFileDlgProc;
|
---|
[4] | 1017 |
|
---|
| 1018 |
|
---|
| 1019 | switch(iMediaType)
|
---|
| 1020 | {
|
---|
| 1021 | case MT_AUDIO:
|
---|
| 1022 | strlcpy(fd.szFullFile, chrLastAudioDir, sizeof(fd.szFullFile));
|
---|
| 1023 | break;
|
---|
| 1024 | case MT_IMAGE:
|
---|
| 1025 | strlcpy(fd.szFullFile, chrLastImageDir, sizeof(fd.szFullFile));
|
---|
| 1026 | break;
|
---|
| 1027 | case MT_VIDEO:
|
---|
| 1028 | strlcpy(fd.szFullFile, chrLastVideoDir, sizeof(fd.szFullFile));
|
---|
| 1029 | break;
|
---|
| 1030 | default:
|
---|
| 1031 | break;
|
---|
| 1032 | }
|
---|
| 1033 |
|
---|
[2] | 1034 | if( (hwndDlg=WinFileDlg( HWND_DESKTOP, HWND_DESKTOP, &fd )) != NULLHANDLE )
|
---|
| 1035 | {
|
---|
| 1036 | if(hBitmap)
|
---|
[104] | 1037 | GpiDeleteBitmap(hBitmap);
|
---|
[2] | 1038 | if( fd.lReturn == DID_OK )
|
---|
| 1039 | {
|
---|
| 1040 | switch(mmIdentifyFile(fd.szFullFile))
|
---|
| 1041 | {
|
---|
| 1042 | case MT_IMAGE:
|
---|
| 1043 | {
|
---|
| 1044 | HOBJECT hObject;
|
---|
| 1045 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
---|
| 1046 | WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
---|
| 1047 | break;
|
---|
| 1048 | }
|
---|
| 1049 | case MT_AUDIO:
|
---|
| 1050 | {
|
---|
| 1051 | HOBJECT hObject;
|
---|
[4] | 1052 |
|
---|
| 1053 | /* Open the audio file in the editor */
|
---|
[2] | 1054 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
---|
[4] | 1055 | WinOpenObject(hObject, ID_MENU_EDITOR, TRUE);
|
---|
| 1056 | // WinOpenObject(hObject, OPEN_DEFAULT, TRUE);
|
---|
[2] | 1057 | break;
|
---|
| 1058 | }
|
---|
| 1059 | case MT_VIDEO:
|
---|
| 1060 | {
|
---|
| 1061 | HOBJECT hObject;
|
---|
| 1062 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
---|
[4] | 1063 | WinOpenObject(hObject, ID_MENU_PLAYER /* OPEN_DEFAULT */, TRUE);
|
---|
| 1064 | #if 0
|
---|
| 1065 | /* Open folder */
|
---|
[104] | 1066 | if(strrchr(fd.szFullFile, '\\')!=NULLHANDLE) {
|
---|
[2] | 1067 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
---|
| 1068 | WinOpenObject(hObject, OPEN_CONTENTS, TRUE);
|
---|
| 1069 | }
|
---|
[4] | 1070 | #endif
|
---|
[2] | 1071 | break;
|
---|
| 1072 | }
|
---|
| 1073 | default:
|
---|
| 1074 | {
|
---|
| 1075 | HOBJECT hObject;
|
---|
| 1076 | char *chr;
|
---|
| 1077 | if((chr=strrchr(fd.szFullFile, '\\'))!=NULLHANDLE) {
|
---|
| 1078 | *chr=0;
|
---|
| 1079 | if((hObject=WinQueryObject(fd.szFullFile))!=NULLHANDLE)
|
---|
| 1080 | WinOpenObject(hObject, OPEN_CONTENTS, TRUE);
|
---|
| 1081 | }
|
---|
| 1082 | break;
|
---|
| 1083 | }
|
---|
| 1084 | }/* switch()*/
|
---|
| 1085 | }/* DID_OK */
|
---|
[4] | 1086 | /* Save the last visited directories */
|
---|
| 1087 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastaudiodir", chrLastAudioDir);
|
---|
| 1088 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastvideodir", chrLastVideoDir);
|
---|
| 1089 | PrfWriteString(NULLHANDLE, chrIniFile, "mmfind", "lastimagedir", chrLastImageDir);
|
---|
[2] | 1090 | }
|
---|
[4] | 1091 | freeResHandle();
|
---|
[2] | 1092 | }
|
---|
| 1093 | WinDestroyMsgQueue(hmq);
|
---|
| 1094 | }
|
---|
| 1095 | WinTerminate(hab);
|
---|
| 1096 | }
|
---|
| 1097 | return 0;
|
---|
| 1098 | }
|
---|
| 1099 |
|
---|