BOOL CStory::Play() /***********************************************************************/ { // returns TRUE if it started playing if (lstrlen(m_szStoryFile)) m_hMCIfile = MCIOpen( App.m_hDeviceWAV, m_szStoryFile, NULL/*lpAlias*/ ); if (m_hMCIfile) { if (m_nRects) { HDC hDC = GetDC(m_hWnd); m_iHighlight = 0 + 1; Story_OnDraw(m_hWnd, hDC, &m_lpWordData[0].rArea, TRUE); ReleaseDC(m_hWnd, hDC); } if (MCIPlay( m_hMCIfile, m_hWnd, 0)) { EnableCursor(FALSE); m_fPlaying = TRUE; SetTimer( m_hWnd, 0xDEAD, 5, NULL ); return(TRUE); } else { MCIClose( m_hMCIfile ); m_hMCIfile = NULL; } } return(FALSE); }
// Start and stop the midi file //************************************************************************ static void StartMidi( BOOL bTurnOn ) //************************************************************************ { static HMCI hPlayMidi; if ( !bTurnOn ) { // turn the sound off if ( hPlayMidi ) { // If playing, stop it MCIClose( hPlayMidi ); hPlayMidi = NULL; } } else { // turn the sound on if ( hPlayMidi ) return; // If already playing, return if ( hPlayMidi = MCIOpen (GetApp()->m_hDeviceMID, TEST_MIDI, NULL/*lpAlias*/) ) { MCILoop( hPlayMidi, TRUE ); if ( !MCIPlay( hPlayMidi, GetApp()->GetMainWnd() ) ) { MCIClose( hPlayMidi ); hPlayMidi = NULL; } } } }
// Start and stop the wave file //************************************************************************ static void StartWave( BOOL bTurnOn ) //************************************************************************ { static HMCI hPlayWave; if ( !bTurnOn ) { // turn the sound off if ( hPlayWave ) { // If playing, stop it MCIClose( hPlayWave ); hPlayWave = NULL; } } else { // turn the sound on if ( hPlayWave ) return; // If already playing, return if ( hPlayWave = MCIOpen (GetApp()->m_hDeviceWAV, TEST_WAVE, NULL/*lpAlias*/) ) { MCILoop( hPlayWave, TRUE ); if ( !MCIPlay( hPlayWave, GetApp()->GetMainWnd() ) ) { MCIClose( hPlayWave ); hPlayWave = NULL; } } } }
BOOL CScene::OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) /************************************************************************/ { // Force the caption flag off for win95 DWORD dwStyle = GetWindowLong( hWnd, GWL_STYLE ); SetWindowLong( hWnd, GWL_STYLE, dwStyle & (~WS_CAPTION) ); // Get the command string STRING szString; GetWindowText( hWnd, szString, sizeof(STRING)-1 ); FNAME szMidi; GetStringParm( szString, 1/*nIndex*/, ',', szMidi ); LPLONG lpSwitches = ExtractSwitches( szString ); // Create the sound class with or w/o wavemix m_pSound = new CSound((BOOL)GetSwitchValue( 'w', lpSwitches)); if (m_pSound) m_pSound->Open( NULL/*"powersnd.dll"*/ ); if ( lpSwitches ) FreeUp( (LPTR)lpSwitches ); // Fix the coordinates from the resource file RepositionDialogControls( hWnd ); // Center the scene within the app's client area CenterWindow( hWnd ); // This should not be necessary, since it's done in the OnClose() if ( m_hMidiTheme ) { // close any looping midi theme MCIClose( m_hMidiTheme ); m_hMidiTheme = NULL; } if ( *szMidi ) { // The scene has a midi theme, so start it LPLONG lpMidiSwitches = ExtractSwitches( szMidi ); if ( m_hMidiTheme = MCIOpen( GetApp()->m_hDeviceMID, szMidi, NULL/*lpAlias*/ ) ) { if ( lpMidiSwitches ) MCILoop( m_hMidiTheme, (BOOL)GetSwitchValue( 'l', lpMidiSwitches ) ); if ( !MCIPlay( m_hMidiTheme, GetApp()->GetMainWnd() ) ) { MCIClose( m_hMidiTheme ); m_hMidiTheme = NULL; } // if it's not looping, it will close itself when it ends } if ( lpMidiSwitches ) FreeUp( (LPTR)lpMidiSwitches ); } // if we have an animation object then setup a timer for it m_idAnimatorTimer = SetTimer(hWnd, ANIMATOR_TIMER_ID, 1, NULL); return(TRUE); }
//************************************************************************ void CBelongsScene::ToonInitDone() //************************************************************************ { STRING szName; ShowDlgItem(m_hWnd, IDC_EDIT, TRUE); UpdateWindow(GetDlgItem(m_hWnd, IDC_EDIT)); SetFocus(GetDlgItem(m_hWnd, IDC_EDIT)); //GetApp()->GetSettingString("Name", szName, "", FALSE); szName[0] = '\0'; if (lstrlen(szName)) { SetDlgItemText(m_hWnd, IDC_EDIT, szName); Edit_SetSel(GetDlgItem(m_hWnd, IDC_EDIT), 0, -1); Edit_SetSel(GetDlgItem(m_hWnd, IDC_EDIT), -1, 0); UpdateWindow(GetDlgItem(m_hWnd, IDC_EDIT)); PlayBelongsTo(NO); FORWARD_WM_COMMAND(m_hWnd, IDC_NEXT, m_hWnd, 0, PostMessage); } else { FNAME szFileName; GetPathName(szFileName, ENTER_NAME_WAVE); if (m_hSound) { MCIStop(m_hSound,YES); MCIClose(m_hSound); m_hSound = NULL; } m_hSound = MCIOpen(GetApp()->m_hDeviceWAV, szFileName, NULL); if (m_hSound) { if (!MCIPlay(m_hSound, m_hWnd)) { MCIClose(m_hSound); m_hSound = NULL; } } } }
LOCAL void Story_OnLButtonDown(HWND hWindow, BOOL fDoubleClick, int x, int y, UINT keyFlags) /***********************************************************************/ { if ( SHIFT ) return; if ( bTrack ) return; PSTORY pStory = GetStory(hWindow); if (!pStory) return; if (pStory->m_fPlaying) return; if (pStory->m_fPlaying) pStory->StopPlaying(); SetCapture( hWindow ); bTrack = TRUE; if ( GetFocus() != hWindow ) SetFocus( hWindow ); bInRect = YES; DWORD dwStyle = GetWindowLong(hWindow, GWL_STYLE); int i; if ((i = pStory->FindHotSpot(x, y)) >= 0) { HDC hDC = GetDC(hWindow); pStory->m_iHighlight = i + 1; Story_OnDraw(hWindow, hDC, &pStory->m_lpWordData[i].rArea, TRUE); if (lstrlen(pStory->m_szStoryFile)) pStory->m_hMCIfile = MCIOpen( App.m_hDeviceWAV, pStory->m_szStoryFile, NULL/*lpAlias*/ ); if ( pStory->m_hMCIfile ) { FORWARD_WM_COMMAND(GetParent(hWindow), GET_WINDOW_ID(hWindow), hWindow, 0, SendMessage); MCIPlay( pStory->m_hMCIfile, NULL, pStory->m_lpWordData[i].dwFrom, pStory->m_lpWordData[i].dwTo ); MCIClose( pStory->m_hMCIfile ); pStory->m_hMCIfile = NULL; } ReleaseDC(hWindow, hDC); } }
static BOOL Video_Open( HWND hWindow, LPVIDEO lpVideo, WORD wDisk, long lStartFrame ) /***********************************************************************/ { if ( !lpVideo ) return( NO ); HourGlass( YES ); // Cleanup any open video file if ( lpVideo->lpSwitches ) { FreeUp( (LPTR)lpVideo->lpSwitches ); lpVideo->lpSwitches = NULL; } if ( lpVideo->idLoopTimer ) { KillTimer( hWindow, lpVideo->idLoopTimer ); lpVideo->idLoopTimer = NULL; } if ( lpVideo->hDevice ) { Video_Close( hWindow, lpVideo ); lpVideo->hDevice = NULL; } FNAME szFileName; GetWindowText( hWindow, szFileName, sizeof(STRING) ); GetStringParm( szFileName, 0/*nIndex*/, ',', szFileName ); lpVideo->lpSwitches = ExtractSwitches( szFileName ); // Replace any %d in the file name with the disk number, // and flag whether we need to check disk labels wsprintf( szFileName, szFileName, wDisk ); BOOL bFullScreen = (BOOL)GetSwitchValue( 'f', lpVideo->lpSwitches ); VideoInit( NO/*ZoomBy2*/, bFullScreen ); if ( !lpVideo->iZoomFactor ) { if ( iDefaultZoomFactor ) lpVideo->iZoomFactor = iDefaultZoomFactor; else { lpVideo->iZoomFactor = (int)GetSwitchValue( 'z', lpVideo->lpSwitches ); if ( !lpVideo->iZoomFactor ) lpVideo->iZoomFactor = 1; } } STRING szAlias; wsprintf( szAlias, "A%d%ld", wDisk, (LPSTR)hWindow ); if ( !(lpVideo->hDevice = MCIOpen( GetApp()->m_hDeviceAVI, szFileName, szAlias, hWindow, lStartFrame )) ) { HourGlass( NO ); return( NO ); } lpVideo->lFrames = MCIGetLength( lpVideo->hDevice ); lpVideo->wDisk = wDisk; //MCISetVideoDrawProc( lpVideo->hDevice, NULL/*lpDrawDibProc*/, NULL/*lpDrawDCProc*/ ); MCISetTimeFormat( lpVideo->hDevice, MCI_FORMAT_FRAMES ); // force the control to take on the size of the video file RECT rect; GetClientRect( hWindow, &rect ); MapWindowPoints( hWindow, GetParent(hWindow), (LPPOINT)&rect, 2 ); SetWindowPos( hWindow, NULL, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, SWP_NOZORDER | SWP_NOACTIVATE ); HourGlass( NO ); return( YES ); }
//************************************************************************ void CBelongsScene::PlayBelongsTo(BOOL fNameOnly) //************************************************************************ { STRING szName; FNAME szNameWave; FNAME szFileName; BOOL fGotName = FALSE; GetDlgItemText(m_hWnd, IDC_EDIT, szName, sizeof(szName)); StripLeadingSpaces(szName); if (!lstrlen(szName)) return; // See if the name is in the table (for names longer than 8) STRING szTheName; int len = lstrlen(szName); for (int n = 0; n <= len; ++n) { if (isspace(szName[n])) szTheName[n] = '-'; else szTheName[n] = szName[n]; } for (int i = 0; i < m_nNames; ++i) { if (!lstrcmpi(m_pNames[i].m_szName, szTheName)) { // found it, now play the wav GetPathName(szNameWave, m_pNames[i].m_szFileName); fGotName = FileExistsExpand(szNameWave, NULL); break; } } // See if file for this name exists // in normal content directory if (!fGotName) { GetPathName(szNameWave, szName); lstrcat(szNameWave, ".wav"); fGotName = FileExistsExpand(szNameWave, NULL); } // Try the windows directory for a custom name if (!fGotName) { GetWindowsDirectory(szNameWave, sizeof(szNameWave)); FixPath(szNameWave); lstrcat(szNameWave, szName); lstrcat(szNameWave, ".wav"); fGotName = FileExistsExpand(szNameWave, NULL); } if (fNameOnly && !fGotName) return; if (m_hSound) { MCIStop(m_hSound,YES); MCIClose(m_hSound); m_hSound = NULL; } if (!fNameOnly) { GetPathName(szFileName, BELONGS_TO_WAVE); if ( m_hSound = MCIOpen(GetApp()->m_hDeviceWAV, szFileName, NULL) ) { MCIPlay(m_hSound, NULL); MCIClose(m_hSound); m_hSound = NULL; } } if (fGotName) { // If we have a name play it if ( m_hSound = MCIOpen(GetApp()->m_hDeviceWAV, szNameWave, NULL) ) { MCIPlay(m_hSound, NULL); MCIClose(m_hSound); m_hSound = NULL; } } else { // Otherwise, play it letter by letter STRING szName; GetDlgItemText(m_hWnd, IDC_EDIT, szName, sizeof(szName)); StripLeadingSpaces(szName); STRING szLetter; FNAME szFileName; BOOL fExists = FALSE; int i = 0; char c; while ( c = szName[i++] ) { szLetter[0] = c; szLetter[1] = '\0'; lstrcat(szLetter, ".wav"); GetPathName(szFileName, szLetter); if ( !FileExistsExpand(szFileName, NULL) ) continue; if ( m_hSound = MCIOpen(GetApp()->m_hDeviceWAV, szFileName, NULL) ) { MCIPlay(m_hSound, NULL); MCIClose(m_hSound); m_hSound = NULL; } } } }