HRESULT CPlayWMV::HandleGraphEvent(void) { LONG evCode = 0, evParam1 = 0, evParam2 = 0; HRESULT hr = S_OK; // Make sure that we don't access the media event interface // after it has already been released. if (!m_pME) return S_OK; // Process all queued events while(SUCCEEDED(m_pME->GetEvent(&evCode, (LONG_PTR *)&evParam1, (LONG_PTR *)&evParam2, 0))) { // If this is the end of the clip, reset to beginning if(EC_COMPLETE == evCode) { LONGLONG pos = 0; // Reset to first frame of movie hr = m_pMS->SetPositions(&pos, AM_SEEKING_AbsolutePositioning , NULL, AM_SEEKING_NoPositioning); if (FAILED(hr)) { // If seeking failed, just stop and restart to reset playback if (FAILED(hr = m_pMC->Stop())) { Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr); break; } if (FAILED(hr = m_pMC->Run())) { Msg(TEXT("Failed(0x%08lx) to reset media clip!\r\n"), hr); break; } } } else if(EC_ERRORABORT == evCode) { Msg(TEXT("Playback error (EC_ERRORABORT - 0x%08lx). Aborting...\r\n"), evParam1); if (FAILED(hr = m_pMC->Stop())) Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr); hr = (HRESULT)evParam1; break; } } // Free memory associated with callback if( FAILED(m_pME->FreeEventParams(evCode, evParam1, evParam2)) ) { CloseClip(); } return hr; }
void OpenClip() { HRESULT hr; // If no filename specified by command line, show file open dialog if(g_szFileName[0] == L'\0') { TCHAR szFilename[MAX_PATH]; UpdateMainTitle(); // If no filename was specified on the command line, then our video // window has not been created or made visible. Make our main window // visible and bring to the front to allow file selection. InitPlayerWindow(); ShowWindow(ghApp, SW_SHOWNORMAL); SetForegroundWindow(ghApp); if (! GetClipFileName(szFilename)) { DWORD dwDlgErr = CommDlgExtendedError(); // Don't show output if user cancelled the selection (no dlg error) if (dwDlgErr) { Msg(TEXT("GetClipFileName Failed! Error=0x%x\r\n"), GetLastError()); } return; } // This sample does not support playback of ASX playlists. // Since this could be confusing to a user, display a warning // message if an ASX file was opened. if (_tcsstr((_tcslwr(szFilename)), TEXT(".asx"))) { Msg(TEXT("ASX Playlists are not supported by this application.\n\n") TEXT("Please select a valid media file.\0")); return; } lstrcpy(g_szFileName, szFilename); } // Reset status variables g_psCurrent = Stopped; g_lVolume = VOLUME_FULL; // Start playing the media file hr = PlayMovieInWindow(g_szFileName, FALSE); // If we couldn't play the clip, clean up if (FAILED(hr) && ( hr != NS_E_LICENSE_REQUIRED ) ) CloseClip(); }
void OpenClip() { HRESULT hr; // If no filename specified by command line, show file open dialog if(g_szFileName[0] == L'\0') { TCHAR szFilename[MAX_PATH]; UpdateMainTitle(); InitPlayerWindow(); SetForegroundWindow(ghApp); if (! GetClipFileName(szFilename)) { DWORD dwDlgErr = CommDlgExtendedError(); // Don't show output if user cancelled the selection (no dlg error) if (dwDlgErr) { Msg(TEXT("GetClipFileName Failed! Error=0x%x\r\n"), GetLastError()); } return; } // This sample does not support playback of ASX playlists. // Since this could be confusing to a user, display a warning // message if an ASX file was opened. if (_tcsnicmp(szFilename, TEXT(".asx"), 4) == 0) { Msg(TEXT("ASX Playlists are not supported by this application.\n\n") TEXT("Please select a valid media file.\0")); return; } StringCchCopy(g_szFileName, NUMELMS(g_szFileName), szFilename); } // Reset status variables g_psCurrent = Stopped; g_lVolume = VOLUME_FULL; EnableWatermarkMenu(TRUE); // Start playing the media file hr = PlayMovieInWindow(g_szFileName); // If we couldn't play the clip, clean up if (FAILED(hr)) CloseClip(); }
void OpenClip() { HRESULT hr; // If no filename specified by command line, show file open dialog if(g_szFileName[0] == L'\0') { TCHAR szFilename[MAX_PATH]; InitPlayerWindow(); SetForegroundWindow(ghApp); if (! GetClipFileName(szFilename)) { DWORD dwDlgErr = CommDlgExtendedError(); // Don't show output if user cancelled the selection (no dlg error) if (dwDlgErr) { Msg(TEXT("GetClipFileName Failed! Error=0x%x\r\n"), GetLastError()); } return; } // This sample does not support playback of ASX playlists. // Since this could be confusing to a user, display a warning // message if an ASX file was opened. if (_tcsstr((_tcslwr(szFilename)), TEXT(".asx"))) { Msg(TEXT("ASX Playlists are not supported by this application.\n\n") TEXT("Please select a valid media file.\0")); return; } lstrcpyn(g_szFileName, szFilename, NUMELMS(g_szFileName)); } EnableTickerMenu(TRUE); // Start playing the media file hr = PlayMovieInWindow(g_szFileName); // If we couldn't play the clip, clean up if (FAILED(hr)) CloseClip(); }
LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: OnPaint(hWnd); break; case WM_DISPLAYCHANGE: if (pWC) pWC->DisplayModeChanged(); break; // Resize the video when the window changes case WM_MOVE: case WM_SIZE: if (hWnd == ghApp) MoveVideoWindow(); break; // Enforce a minimum size case WM_GETMINMAXINFO: { LPMINMAXINFO lpmm = (LPMINMAXINFO) lParam; if (lpmm) { lpmm->ptMinTrackSize.x = MINIMUM_VIDEO_WIDTH; lpmm->ptMinTrackSize.y = MINIMUM_VIDEO_HEIGHT; } } break; case WM_KEYDOWN: switch(toupper((int) wParam)) { case VK_ESCAPE: case VK_F12: CloseClip(); break; } break; case WM_COMMAND: switch(wParam) { // Menus case ID_FILE_OPENCLIP: // If we have ANY file open, close it and shut down DirectShow CloseClip(); OpenClip(); // Open the new clip break; case ID_FILE_INITCLIP: OpenClip(); break; case ID_FILE_EXIT: CloseClip(); PostQuitMessage(0); break; case ID_FILE_CLOSE: CloseClip(); break; case ID_DISABLE: FlipFlag(MARK_DISABLE); DisableTicker(g_dwTickerFlags); break; case ID_SLIDE: FlipFlag(MARK_SLIDE); SlideTicker(g_dwTickerFlags); break; case ID_TICKER_STATIC_IMAGE: g_dwTickerFlags |= MARK_STATIC_IMAGE; g_dwTickerFlags &= ~(MARK_DYNAMIC_TEXT); BlendApplicationImage(ghApp); CheckMenuItem(ghMenu, ID_TICKER_STATIC_IMAGE, MF_CHECKED); CheckMenuItem(ghMenu, ID_TICKER_DYNAMIC_TEXT, MF_UNCHECKED); break; case ID_TICKER_DYNAMIC_TEXT: g_dwTickerFlags |= MARK_DYNAMIC_TEXT; g_dwTickerFlags &= ~(MARK_STATIC_IMAGE); BlendApplicationText(ghApp, g_szAppText); CheckMenuItem(ghMenu, ID_TICKER_STATIC_IMAGE, MF_UNCHECKED); CheckMenuItem(ghMenu, ID_TICKER_DYNAMIC_TEXT, MF_CHECKED); break; case ID_SET_FONT: g_hFont = UserSelectFont(); // Change the current font PostMessage(ghApp, WM_COMMAND, ID_TICKER_DYNAMIC_TEXT, 0); break; case ID_SET_TEXT: DialogBox(ghInst, MAKEINTRESOURCE(IDD_DIALOG_TEXT), ghApp, (DLGPROC) TextDlgProc); break; case ID_HELP_ABOUT: DialogBox(ghInst, MAKEINTRESOURCE(IDD_HELP_ABOUT), ghApp, (DLGPROC) AboutDlgProc); break; } // Menus break; case WM_GRAPHNOTIFY: HandleGraphEvent(); break; case WM_CLOSE: SendMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } // Window msgs handling return DefWindowProc(hWnd, message, wParam, lParam); }
LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { // Resize the video when the window changes case WM_MOVE: case WM_SIZE: if ((hWnd == ghApp) && (!g_bAudioOnly)) MoveVideoWindow(); break; // Enforce a minimum size case WM_GETMINMAXINFO: { LPMINMAXINFO lpmm = (LPMINMAXINFO) lParam; lpmm->ptMinTrackSize.x = MINIMUM_VIDEO_WIDTH; lpmm->ptMinTrackSize.y = MINIMUM_VIDEO_HEIGHT; } break; case WM_KEYDOWN: switch(toupper((int) wParam)) { // Frame stepping case VK_SPACE: case '1': StepOneFrame(); break; // Frame stepping (multiple frames) case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': StepFrames((int) wParam - '0'); break; case 'P': PauseClip(); break; case 'S': StopClip(); break; case 'M': ToggleMute(); break; case 'F': case VK_RETURN: ToggleFullScreen(); break; case 'H': InitVideoWindow(1,2); CheckSizeMenu(wParam); break; case 'N': InitVideoWindow(1,1); CheckSizeMenu(wParam); break; case 'D': InitVideoWindow(2,1); CheckSizeMenu(wParam); break; case 'T': InitVideoWindow(3,4); CheckSizeMenu(wParam); break; case VK_ESCAPE: if (g_bFullscreen) ToggleFullScreen(); else CloseClip(); break; case VK_F12: case 'Q': case 'X': CloseClip(); break; } break; case WM_COMMAND: switch(wParam) { // Menus case ID_FILE_OPENCLIP: // If we have ANY file open, close it and shut down DirectShow if (g_psCurrent != Init) CloseClip(); // Open the new clip OpenClip(); break; case ID_FILE_EXIT: CloseClip(); PostQuitMessage(0); break; case ID_FILE_PAUSE: PauseClip(); break; case ID_FILE_STOP: StopClip(); break; case ID_FILE_CLOSE: CloseClip(); break; case ID_FILE_MUTE: ToggleMute(); break; case ID_FILE_FULLSCREEN: ToggleFullScreen(); break; case ID_HELP_ABOUT: DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUTBOX), ghApp, (DLGPROC) AboutDlgProc); break; case ID_FILE_SIZE_HALF: InitVideoWindow(1,2); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_NORMAL: InitVideoWindow(1,1); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_DOUBLE: InitVideoWindow(2,1); CheckSizeMenu(wParam); break; case ID_FILE_SIZE_THREEQUARTER: InitVideoWindow(3,4); CheckSizeMenu(wParam); break; case ID_SINGLE_STEP: StepOneFrame(); break; } // Menus break; case WM_GRAPHNOTIFY: HandleGraphEvent(); break; case WM_CLOSE: SendMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } // Window msgs handling // Pass this message to the video window for notification of system changes if (pVW) pVW->NotifyOwnerMessage((LONG_PTR) hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam); }
HRESULT HandleGraphEvent(void) { LONG evCode, evParam1, evParam2; HRESULT hr=S_OK; // Make sure that we don't access the media event interface // after it has already been released. if (!pME) return S_OK; // Process all queued events while(SUCCEEDED(pME->GetEvent(&evCode, (LONG_PTR *) &evParam1, (LONG_PTR *) &evParam2, 0))) { // If this is the end of the clip, reset to beginning if(EC_COMPLETE == evCode) { LONGLONG pos=0; // Reset to first frame of movie hr = pMS->SetPositions(&pos, AM_SEEKING_AbsolutePositioning , NULL, AM_SEEKING_NoPositioning); if (FAILED(hr)) { // Some custom filters (like the Windows CE MIDI filter) // may not implement seeking interfaces (IMediaSeeking) // to allow seeking to the start. In that case, just stop // and restart for the same effect. This should not be // necessary in most cases. if (FAILED(hr = pMC->Stop())) { Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr); break; } if (FAILED(hr = pMC->Run())) { Msg(TEXT("Failed(0x%08lx) to reset media clip!\r\n"), hr); break; } } } else if(EC_ERRORABORT == evCode) { Msg(TEXT("Playback error (EC_ERRORABORT - 0x%08lx). Aborting...\r\n"), evParam1); if (FAILED(hr = pMC->Stop())) Msg(TEXT("Failed(0x%08lx) to stop media clip!\r\n"), hr); hr = (HRESULT) evParam1; break; } else if( EC_WMT_EVENT == evCode ) { AM_WMT_EVENT_DATA *pEventData = (AM_WMT_EVENT_DATA *)evParam2; hr = HandleWMTEvent(pEventData, evParam1); } } // Free memory associated with callback if( FAILED(pME->FreeEventParams(evCode, evParam1, evParam2)) ) { CloseClip(); } return hr; }
LRESULT CALLBACK WndMainProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_PAINT: OnPaint(hWnd); break; case WM_DISPLAYCHANGE: if (pWC) pWC->DisplayModeChanged(); break; // Resize the video when the window changes case WM_MOVE: case WM_SIZE: if (hWnd == ghApp) MoveVideoWindow(); break; // Enforce a minimum size case WM_GETMINMAXINFO: { LPMINMAXINFO lpmm = (LPMINMAXINFO) lParam; if (lpmm) { lpmm->ptMinTrackSize.x = MINIMUM_VIDEO_WIDTH; lpmm->ptMinTrackSize.y = MINIMUM_VIDEO_HEIGHT; } } break; case WM_KEYDOWN: switch(toupper((int) wParam)) { case 'P': PauseClip(); break; case 'S': StopClip(); break; case 'M': ToggleMute(); break; case VK_ESCAPE: case VK_F12: case 'Q': case 'X': CloseClip(); break; } break; case WM_COMMAND: switch(wParam) { // Menus case ID_FILE_OPENCLIP: // If we have ANY file open, close it and shut down DirectShow if (g_psCurrent != Init) CloseClip(); // Open the new clip OpenClip(); break; case ID_FILE_EXIT: CloseClip(); PostQuitMessage(0); break; case ID_FILE_PAUSE: PauseClip(); break; case ID_FILE_STOP: StopClip(); break; case ID_FILE_CLOSE: CloseClip(); break; case ID_FILE_MUTE: ToggleMute(); break; case ID_FLIP: FlipFlag(MARK_FLIP); FlipWatermark(g_dwWatermarkFlags); break; case ID_MIRROR: FlipFlag(MARK_MIRROR); MirrorWatermark(g_dwWatermarkFlags); break; case ID_DISABLE: FlipFlag(MARK_DISABLE); DisableWatermark(g_dwWatermarkFlags); break; case ID_ANIMATE: FlipFlag(MARK_ANIMATE); AnimateWatermark(g_dwWatermarkFlags); break; case ID_SLIDE: FlipFlag(MARK_SLIDE); SlideWatermark(g_dwWatermarkFlags); break; case ID_STROBE: FlipFlag(MARK_STROBE); StrobeWatermark(g_dwWatermarkFlags); break; case ID_ALL_EFFECTS: SetAllEffects(); break; case ID_NO_EFFECTS: ClearAllEffects(); break; case ID_HELP_ABOUT: DialogBox(ghInst, MAKEINTRESOURCE(IDD_ABOUTBOX), ghApp, (DLGPROC) AboutDlgProc); break; } // Menus break; case WM_GRAPHNOTIFY: HandleGraphEvent(); break; case WM_CLOSE: SendMessage(ghApp, WM_COMMAND, ID_FILE_EXIT, 0); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } // Window msgs handling return DefWindowProc(hWnd, message, wParam, lParam); }
// // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_SIZE: ResizeClip (); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); break; case ID_OPEN_CLIP: OpenClip(); break; case ID_CLOSE_CLIP: CloseClip(); break; case ID_PAUSE: PausePlayClip(); break; case ID_MUTE: MuteClip(); break; case ID_SIZE_FULLSCREEN: FullScreen(); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_KEYDOWN: switch(toupper((int) wParam)) { case 'P': PausePlayClip(); break; case 'S': break; case 'M': MuteClip(); break; case 'F': case VK_RETURN: FullScreen(); break; case 'B': ClipBegin (); break; case 'H': //InitVideoWindow(1,2); //CheckSizeMenu(wParam); break; case 'N': //InitVideoWindow(1,1); //CheckSizeMenu(wParam); break; case 'D': //InitVideoWindow(2,1); //CheckSizeMenu(wParam); break; case 'T': //InitVideoWindow(3,4); //CheckSizeMenu(wParam); break; case VK_ESCAPE: if (videoStream.IsValid() && videoStream->IsFullscreen()) { FullScreen(); } else { CloseClip(); } break; case VK_F12: case 'Q': case 'X': CloseClip(); break; } break; case WM_PAINT: { if (videoStream.IsValid()) { //videoStream->Repaint(); } else { hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rcClient; //RECT rcToolbar; GetClientRect(hWnd, &rcClient); //GetClientRect(toolbar, &rcToolbar); HRGN hRgn1 = CreateRectRgnIndirect(&rcClient); //HRGN hRgn2 = CreateRectRgnIndirect(&rcToolbar); //CombineRgn(hRgn1, hRgn1, hRgn2, RGN_DIFF); //::PaintRgn(hdc, hRgn2); FillRgn(hdc, hRgn1, brush); DeleteObject(hRgn1); //DeleteObject(hRgn2); EndPaint(hWnd, &ps); } break; } case WM_DESTROY: PostQuitMessage(0); break; case DSHOW: // HandleGraphEvent(); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return FALSE; }